简体   繁体   English

mongo db find操作查询不起作用

[英]mongo db find operation query is not working

Am new to mongodb 是mongodb的新手

db.myjobs.find() gets following results db.myjobs.find()得到以下结果

{ "_id" : ObjectId("52849a7b8dd61980d1b49b87"), "browser" : "FF20", "id" : "70", "jobs" : [ { "_id" : "5281d1680d0f2f2aaec5787e",   "date" : "Tue Nov 12 2013 12:27:44 GMT+0530 (IST)", "id" : "29" } ],  "os" : "VM-WIN7-64", "server" : "172.16.2.120" }

from the above result i have to return "os" : "VM-WIN7-64" on the basis of id=29 inside jobs 从以上结果中,我必须基于jobs内部id=29返回"os" : "VM-WIN7-64"

am using following code and it is not correct. 我正在使用以下代码,这是不正确的。

db.myjobs.find( { id: 29 } )

How can i get "os" : "VM-WIN7-64" by inputting id (id=29) inside jobs no need to get os details using "id":"70" 如何通过在jobs输入id (id = 29)来获得"os" : "VM-WIN7-64" ,而无需使用"id":"70"获取os详细信息"id":"70"

Like this: 像这样:

db.myjobs.find( { "jobs.id": "29" } )

MongoDB doesn't perform recursive searches so if want to find field in nested document you have to provide a path to the field using dot notation. MongoDB不执行递归搜索,因此,如果要在嵌套文档中查找字段,则必须使用点表示法提供该字段的路径。

Moreover fields in MongoDB are typed so string "29" is not equal to number 29 此外,在MongoDB中键入字段,因此字符串"29"不等于数字29

You can use dot operator to go inside of the object. 您可以使用点运算符进入对象内部。

db.myjobs.find({
   "jobs.id": "29"
})

The following should work 以下应该工作

db.myjobs.find({"jobs.id":"29"},{"_id":0,"os":1}) db.myjobs.find({ “jobs.id”: “29”},{ “_ ID”:0, “OS”:1})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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