Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python MongoDB的最短查询_Python_Json_Mongodb - Fatal编程技术网

Python MongoDB的最短查询

Python MongoDB的最短查询,python,json,mongodb,Python,Json,Mongodb,我有以下mongodb条目: { “someKey”:“someValue”, “数组”:[ {'name':'test1', “值”:“值1” }, {'name':'test2', “值”:“值2” } ] } 由于您正在查询元素数组,并且希望筛选出的元素只是展开并匹配: db.CollectionName.aggregate( [ { $unwind : "$array" } ,{$match:{'array.name':'test1'}} ]) 这将为您提供如下结果: {

我有以下mongodb条目:

{ “someKey”:“someValue”, “数组”:[ {'name':'test1', “值”:“值1” }, {'name':'test2', “值”:“值2” } ]
} 由于您正在查询元素数组,并且希望筛选出的元素只是展开并匹配:

db.CollectionName.aggregate( [ { $unwind : "$array" } ,{$match:{'array.name':'test1'}} ]) 
这将为您提供如下结果:

{
    "_id" : ObjectId("59df5b30646afdfce4084152"),
    "someKey" : "someValue",
    "array" : {
        "name" : "test1",
        "value" : "value1"
    }
}