Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.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
Mongodb 如何从PyMongo中获取不同的值_Mongodb_Python 2.7_Pymongo - Fatal编程技术网

Mongodb 如何从PyMongo中获取不同的值

Mongodb 如何从PyMongo中获取不同的值,mongodb,python-2.7,pymongo,Mongodb,Python 2.7,Pymongo,在MongoDB中,我有一个存储数据集。 使用PyMongo,我在一个集合中查找所有不同/唯一的值 for testy in collection.distinct('stores'): print(testy) 我还可以找到我感兴趣的拼写错误商店的子集 for testy in collection.find({'stores': {'$in': ['Aldi','ALDI','aldi']}}): 我想做的是在这个子集中找到唯一的 根据MongoDB文档 db.runCommand (

在MongoDB中,我有一个存储数据集。 使用PyMongo,我在一个集合中查找所有不同/唯一的值

for testy in collection.distinct('stores'):
print(testy)
我还可以找到我感兴趣的拼写错误商店的子集

for testy in collection.find({'stores': {'$in': ['Aldi','ALDI','aldi']}}):
我想做的是在这个子集中找到唯一的

根据MongoDB文档

db.runCommand ( { distinct: "inventory", key: "item.sku", query: { dept: "A"} } )

尝试了很多组合,添加查询时使用了
$in
,但无法使其正常工作。

您要查找的是

for testy in collection.find().distinct('stores'):
    print(testy)
for testy in collection.distinct('stores', {'dept': 'A'}):
    print(testy)