Here is the mongo Document.
what code do i need to extract all data with associated token.
{
"_id": {
"$oid": "59cfb47b78a26d86cc5fdd7a"
},
"event": "Coding",
"data": [
{
"first_name": "Chanchal",
"last_name": "Roshan",
"email": "chan@gmail.com",
"phone": "75044",
"college": "AIT",
"members": "1",
"amount": "25",
"branch": "IT",
"token": "684695669",
"event": "Coding"
},
{
"first_name": "Ravi",
"last_name": "Raj",
"email": "i@gmail.com",
"phone": "89746",
"college": "AIT",
"members": "1",
"amount": "250",
"branch": "IT",
"token": "128027522",
"event": "Coding"
}
],
"auth_token": "z1iZ0LnDHFhs48PlYjNHyCjeh7y1"
I am assuming you mean given token XXX
, find all documents where an element of the data
array contains token="XXX"
and return just that element of the array, not the whole array. This should work. Note data.token
and the use of the $
positional operator in the projection (arg 2):
db.foo.find({"data.token":"XXX"},{"data.$":1});