What Javascript library can evaluate MongoDB-like query predicates against an object?

前端 未结 5 1955
说谎
说谎 2020-12-15 06:42

Is there a javascript library that will allow me to express object predicates in a DSL similar to MongoDB\'s query language? For the sake of clarity in a large program, I\'d

相关标签:
5条回答
  • 2020-12-15 07:26

    OK I found the answer: Sift.js

    Now for the long answer: This has been asked and answered before. The salient points are:

    • Use Sift if you really want Mongo syntax
    • If you want to be more mainstream, use Underscore.js like everyone else. It has heaps of handy functions in addition to the fact that it basically does what sift does with a slightly different syntax.
    • You may not need any library at all - modern browsers support many useful functions directly on the Array prototype, like filter() for example.

    As a final note, mongodb-riff appears to be trying to do something similar but currently the page states clearly that it doesn't work - perhaps it's abandoned. But his readme is at least of value :-), he mentions sift and Query Engine which looks more mature, though too complicated for me!

    Personally I'm going to go with Underscore because now that I've looked into it for the first time, I realise that it has heaps of handy stuff I need, plus I really only wanted to do simple functions like what would be _.find() in Underscore. But I guess if you want to do more complicated mongo-like queries, you'll do it in less LOC with Sift.

    0 讨论(0)
  • 2020-12-15 07:26

    lodash.js

    You want to use lodash.js. Its a drop in replacement for underscore.js. The performance is twice as fast.

    http://lodash.com/

    0 讨论(0)
  • 2020-12-15 07:28

    https://github.com/mirek/node-json-criteria library does exactly that - evaluates criteria queries on JSON objects using MongoDB query format.

    0 讨论(0)
  • Check out Mingo

    I implemented it after finding no suitable alternative.

    It is still actively being developed but is usable. Test coverage is not complete.

    Usable from both browser and nodejs

    [Edit]

    This library is now the most complete implementation of MongoDB's query language for the frontend.

    0 讨论(0)
  • 2020-12-15 07:45

    The closest I could find was linq.js, which is LINQ for JavaScript. Hopefully this will be of some help to you.

    0 讨论(0)
提交回复
热议问题