简体   繁体   中英

How to check NotEquals/Exists in Meteor Collection?

I'm trying to use a Meteor app to get documents from a mongodb database (using Meteor's Collection), but I only want documents that have a certain note field does not exist in it.

I tried to do:

Documents.findOne({id:'abcd',note:{"$exists":'true'}});

where documents is my Collection but it returns the first found result (which doesn't have a note field) rather than the one I need. I also tried using $exists but that doesn't work either.

Can someone please help me out here? I'm guessing I'm making a really silly error somewhere, but I just can't put my finger on it

Thanks in advance :)

Try

Documents.findOne({id:'abcd',note:{"$exists":true}});

Remember the true is parsed as a boolean in JSON only if it doesn't have encapsulated quotes

Try taking out the quotes around $exists. Like

Documents.findOne({id: 'abcd', note:{ $exists: true}});

That should work. Also, in case you didn't know, the docs are great for mongodb.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM