mongodb - Match a field property containing $ in the name -


i saved lot of aggregations pipeline collection :

   {         "_id" : objectid("56d06614070b7f2b117b23db"),         "ops" : [             {                 "$unwind" : "$x"             },             {                 "$unwind" : "$y"             },             {                 "$match" : {                     "brand" : "z"                 }             }         ]     } 

i want make statistics on data :

db.apicalls.aggregate([{"$unwind":"$ops"},{"$match":{***...***}}]) 

the result unwind operation alone :

{ "_id" : objectid("56d06631070b7f11117b23d4"), "ops" : { "$match" : { "brand" : "zzz" } } }, { "_id" : objectid("56d06631070b7f11117b23d4"), "ops" : { "$unwind" : "$x" } } 

i want able match $match operations saved collection. haves how select on key "$match" ?

thanks

your question misleading. since $ characters "illegal" property names in mongodb document, "escaped" "slash" \:

{     "_id" : objectid("56d06614070b7f2b117b23db"),     "ops" : [         {             "\$unwind" : "$x"         },         {             "\$unwind" : "$y"         },         {             "\$match" : {                     "brand" : "z"             }         }     ] } 

therefore need include characters in key using $exists operator find \$match:

db.apicalls.aggregate([   { "$unwind": "$ops" },   { "$match": {     "ops.\\$match": { "$exists": true }   }} ]) 

which returns correct document:

{ "_id" : objectid("56d06614070b7f2b117b23db"), "ops" : { "\$match" : { "brand" : "z" } } } 

Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -