[英]how to specify a var field in mongodb find
In mongodb, I want to find a document which exist a field returned by a function. 在mongodb中,我想找到一个文档,该文档存在一个函数返回的字段。 for example:
例如:
var field = func()
var cur = db.test.find({field:{$exists:1}}).limit(1)
Mongodb to find a document has a field named "field", but I want to find a document has a field named the value of the var "field". Mongodb查找文档有一个名为“ field”的字段,但是我想查找文档中有一个名为var“ field”的值的字段。 what shoud I do.
我该怎么办。 Thankd you very much.
非常感谢你
Use this 用这个
db.CollectionName.find({},{FieldName:1})
in case I want to have results of students who have field named age in their document. 如果我想获得在文档中具有年龄字段名称的学生的成绩。
db.CollectionName.find({},{age:1}) // will result all documents with age in their field
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.