I want to use the query in mongo db in SQL:
Select * from Users where familyId =@X and (isDeleted =false or isDeleted is null)
Already I have the first condition, I don’t know how to mix it with the And-Or
var myMembers = Meteor.users.find({ "profile.family_id": Meteor.user().profile.family_id });
How should it be possible?
1> chridam..:
You can use the $and
operator Explicit query:
var family_id = Meteor.user().profile.family_id, myMembers = Meteor.users.find({ "$and": [ { "profile.family_id": family_id }, { "$or": [ { "isDeleted": false }, { "isDeleted": null } /* or { "isDeleted": { "$exists": false } } */ ] } ] });
Or implicitly by specifying a comma-separated expression:
var family_id = Meteor.user().profile.family_id, myMembers = Meteor.users.find({ "profile.family_id": family_id, "$or": [ { "isDeleted": false }, { "isDeleted": null } /* or { "isDeleted": { "$exists": false } } */ ] });
Note: To check whether a field exists, you can use the $exists
operator, { "isDeleted": { "$ exists": false } }
Because { isDeleted : null }
the query matches fields containing isDeleted
whose value is null or does not contain the isDeleted
field Documentation of the field.