1
一個MongoDB的查詢下面的查詢MongoDB中殼工作:如何編寫pymongo
db.user.count({$and: [ {"agent_id":{$exists:true}}, {"is_agent":{$ne:true}} ] })
當我嘗試在Python中,我得到了不同的答案。這裏是python代碼:
import pymongo
from pymongo import MongoClient
def getCollection(cient,dbname,collection):
"""Return a colleciton based on client, db and collection"""
data_base = getattr(client, dbname)
collObject = getattr(data_base, collection)
return collObject
userColl = getCollection(client, "hkpr_restore","user")
usersWithAgents = userColl.count({"$and": [ {"agent_id":{"$exists":"true"}}, {"is_agent":{"$ne":"true"}} ] })
print usersWithAgents
對於mongo shell查詢結果約爲11,000,對python腳本查詢結果約爲17,000。
你能更具體地說明你如何得到不同的答案嗎? –
對於一個mongo shell查詢約爲11,000,對於python腳本查詢約爲17,000。 – dwstein