2

这是我的 mongodb 文档:

{ "FRIENDS" : [     
    { "LOC" : "13.039064033333332,77.5547927", "NAME" : "A1", "PHONE_NUMBER" : "817361155" } ],
 "MYID" : "349512956", 
"MYLOCATION" : "13.0389541,77.5549799", 
"OCCASION" : "cafe", 
"_id" : ObjectId("503d87150f43159357000001"), 
"average" : "13.0389541,77.5549799" }

这是我的查询

> db.test_collection.find({"MYID":"349512956"},{"FRIENDS.PHONE_NUMBER":"817361155"});

和输出

{ "FRIENDS" : [ { "PHONE_NUMBER" : "817361155" } ], "_id" : ObjectId("503d87150f43159357000001") }

但是,我希望结果中包含整个朋友文档。地点、姓名、电话号码。我如何得到这些?任何帮助将不胜感激。我正在搜索 monogo 文档,但找不到我的答案。

4

2 回答 2

3

试试这个

// i.e., select * from things where MYID=somethig and PHONE_NUMBER="foo"
db.test_collection.find({"MYID":"349512956", "FRIENDS.PHONE_NUMBER":"817361155"});
于 2012-08-31T12:47:04.683 回答
0

更具体地说,第二个参数选择要输出的字段。看下面的实际实现:

> db.test_collection.find
function (query, fields, limit, skip, batchSize, options) {
    return new DBQuery(this._mongo, this._db, this, this._fullName, 
           this._massageObject(query), fields, limit, skip, batchSize, options || 
           this.getQueryOptions());
}
于 2012-08-31T13:31:09.967 回答