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.
我正在尝试使用Meteor应用程序从mongodb数据库中获取文档(使用Meteor的集合),但我只希望文档中不存在具有某个注释字段的文档。
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.
文件是我的集合,但它返回第一个找到的结果(没有注释字段)而不是我需要的结果。我也试过使用$ exists但是这也不起作用。
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 :)
提前致谢 :)
2 个解决方案
#1
6
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
请记住,只有在没有封装引号的情况下,true才会被解析为JSON中的布尔值
#2
2
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.
这应该工作。此外,如果您不知道,文档对mongodb很有用。
#1
6
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
请记住,只有在没有封装引号的情况下,true才会被解析为JSON中的布尔值
#2
2
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.
这应该工作。此外,如果您不知道,文档对mongodb很有用。