我的$ne : ""
与pymongo无法正常工作。
hashtable['ACR-WEB-01']=db.logs.find({"host_name" : "WEB-01"}, {"service_description": {"$ne" : ""}}).distinct("service_description")
print hashtable['ACR-WEB-01']
印刷的结果是:
[u'Disks', u'', u'Mem', u'VM Tools', u'Cpu', u'vm-alarm-CPU', u'vm-alarm-MEM', u'vm-alarm-VMTOOLS', u'Uptime']
如你所见,我得到u''
为什么?
如果我直接在mongodb中执行此操作,它可以工作:
> db.logs.distinct( "service_description" , { "host_name" : "WEB-01", service_description: {$ne : ""}} )
[
"Cpu",
"Disks",
"Mem",
"Uptime",
"VM Tools",
"vm-alarm-CPU",
"vm-alarm-MEM",
"vm-alarm-VMTOOLS"
]
感谢您的帮助
答案 0 :(得分:3)
您需要将两个find
查询字词放入相同的哈希对象中:
hashtable['ACR-WEB-01']=db.logs
.find({"host_name": "WEB-01", "service_description": {"$ne" : ""}})
.distinct("service_description")