Is there a way to use MongoDB query objects to filter regular JavaScript arrays?

后端 未结 5 691
独厮守ぢ
独厮守ぢ 2021-02-08 22:02

In MongoDB, you can use JSON-style objects such as in the following to query a collection:

db.things.find({ x : { $ne : 3 }, y : \'foo\' });

I\

5条回答
  •  礼貌的吻别
    2021-02-08 22:32

    I dont think you can just use the mongodb filters in normal js arrays. Because you need to understand the fact that

    The filters specified in mongodb are evaluated in mongodb indexes not in the javascript result set

    Means the filters evaluated(translated) to query against a index not the js. So what you are asking is a DSL on top of mongodb(or JS) which will evaluate the mongodb index filters in the JS array.

    I dont think its needed since both serves the different purposes (Though its possible(difficult) to write custom DSL). Also there are major frameworks like underscore.js already provide a ways to handle these.

提交回复
热议问题