node.js - $all mongodb node js -
i implementing search keywords mongodb , node js, see there operator $all in mongo selects documents field holds array , contains elements.
here source code node js
exports.find = function(req, res) { var b=req.params.search; var query = {}; var cadsrch = b.split(' '); var l = cadsrch.length; var = 0; (i = 0; < l; i++) { if(cadsrch[i]!=''){ query[i]=new regexp('^'+cadsrch[i], 'i'); } } db.collection('publicacion', function(err, collection) { collection.find({tags: {'$all':query}},{title:true,content:true}).limit(5).toarray(function(err, items) { res.jsonp(items); }); }); };
the above source not work, query works in mongo->
db.publication.find({tags:{$all:['chevrolet','car']}})
and strange '$in' instead '$all' works, useful work '$all' implement exact searches
you have defined query object {}
. however, example use in mongo shell has array []
.
i know "kind of" same thing, it's worth making these same type.
Comments
Post a Comment