2

Here's my mongodb document:

{ "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" }

Here's my query

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

and the output

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

However, I want the entire friend document included in the result. LOC, NAME, PHONE_NUMBER. How do I get these ? Any help will be greatly appreciated. I'm searching through the monogo docs but am unable to find my answer.

2 Answers 2

3

Try this

// i.e., select * from things where MYID=somethig and PHONE_NUMBER="foo"
db.test_collection.find({"MYID":"349512956", "FRIENDS.PHONE_NUMBER":"817361155"});
Sign up to request clarification or add additional context in comments.

Comments

0

To be more specific, the second argument selects the fields that you want outputted. See the actual implementation below:

> 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());
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.