आपको जो चाहिए वह है "aggregation"
और $map
और $setDifference
कोड>
ऑपरेटरों
db.collection.aggregate([
{
"$match": {
"node.-user": "Zulu99",
"node.-lat": "-37.6787103"
}
},
{
"$project": {
"node": {
"$setDifference": [{
"$map": {
"input": "$node",
"as": "n",
"in": {
"$cond": [
{ "$eq": [ "$$n.-user", "Zulu99" ]},
"$$n",
false
]
}
}
},
[false]]
}
}
}
])
MongoDB 3.2 से आप $filter
. का उपयोग कर सकते हैं ऑपरेटर
db.collection.aggregate([
{
"$match": {
"node.-user": "Zulu99",
"node.-lat": "-37.6787103"
}
},
{ "$project": {
"node": {
"$filter": {
"input": "$node",
"as": "n",
"cond": { "$eq": [ "$$node.n", "Zulu99" ] }
}
}
}}
])
जो पैदावार:
{
"_id" : ObjectId("55acf6187d4c31475417fa62"),
"node" : [
{
"-id" : "60648717",
"-uid" : "46482",
"-user" : "Zulu99",
"-lat" : "-37.6796337",
"-lon" : "144.9220639",
"-timestamp" : "2009-12-12T21:29:36Z",
"-visible" : "true",
"-version" : "2",
"-changeset" : "3358816"
},
{
"-id" : "60648718",
"-timestamp" : "2009-12-12T21:29:35Z",
"-uid" : "46482",
"-version" : "2",
"-changeset" : "3358816",
"-user" : "Zulu99",
"-visible" : "true",
"-lat" : "-37.6787103",
"-lon" : "144.9224609"
}
]
}