Mongodb 如何从PyMongo中获取不同的值
在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 (
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)