Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB $or query in Meteor?

Tags:

mongodb

meteor

The mongodb $or operator works as intended outside of a meteorjs context:

db.users.find({$or: [{email: '[email protected]'},{city: 'atlanta'}]});

I get results for any document that has email [email protected] or city of atlanta.

The same query in Meteor syntax doesn't yield the same results :

Users = new Meteor.Collection("users");
Users.find({$or: [{email: '[email protected]'},{city: 'atlanta'}]});

I've read the meteor docs - http://docs.meteor.com/#find - and since it doesn't say anything about it, I'm assuming it should run just the same as a mongodb 1.6+ instance?

like image 238
gamengineers Avatar asked Jan 10 '13 23:01

gamengineers


1 Answers

find returns a cursor object. You need to use a fetch to get the array of values. Try:

console.log(Users.find({$or: [{email: '[email protected]'},{city: 'atlanta'}]}).fetch());
like image 145
mjhm Avatar answered Oct 05 '22 02:10

mjhm