这是我的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") }
但是,我希望结果中包含整个朋友文档。 LOC,NAME,PHONE_NUMBER。我怎么得到这些?任何帮助将不胜感激。我正在搜索monogo文档,但无法找到我的答案。
答案 0 :(得分:3)
试试这个
// i.e., select * from things where MYID=somethig and PHONE_NUMBER="foo"
db.test_collection.find({"MYID":"349512956", "FRIENDS.PHONE_NUMBER":"817361155"});
答案 1 :(得分: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());
}