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

后端 未结 5 688
独厮守ぢ
独厮守ぢ 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:22

    Ok, so here's another try:

    sift.js (npm: sift) by Craig Condon is a MongoDB-inspired array filtering library. It’s a bit like an alternative to Underscore for people who love MongoDB. Sift.js supports operators like $in and $gt, but can also filter arrays based on functions and even works with deeply-nested objects in arrays.

    Craig has provided a few examples that should look familiar to Mongo users:

    var sift = require('sift');
    
    sift({ $in: ['hello','world'] }, ['hello','sifted','array!']); //
    ['hello']
    

    Source: http://dailyjs.com/2012/01/04/node-roundup/

提交回复
热议问题