4
이 내 코드입니다 :
File "./rapport.py", line 23
services = db.logs.distinct("service_description" , { "service_description" : { $ne : null } })
^
SyntaxError: invalid syntax
내가 왜 내 코드에서 "$ne : null"
를 사용할 수 없습니다
#! /usr/bin/python
import os
from pymongo.connection import Connection
from pymongo.master_slave_connection import MasterSlaveConnection
database = 'toto'
collection = 'logs'
master = Connection(host="X.X.X.X", port=27017)
slave1 = Connection(host="X.X.X.X", port=27017)
con = MasterSlaveConnection(master, slaves=[slave1, master])
db = getattr(con,database)
#host_name.append("getattr(db,collection).distinct('host_name')")
#print host_name[1]
hosts = db.logs.distinct('host_name')
services = db.logs.distinct("service_description" , { "service_description" : { $ne : null } })
#print hosts
print services
나는이 오류가있어? 나는이 쿼리를 실행할 때 mongodb에서 직접 "db.logs.distinct("service_description" , { "service_description" : { $ne : null } })"
을 실행하기 때문에 이해하지 못한다.
services = db.logs.distinct("service_description", { "service_description" : { "$ne" : None } })
감사합니다.
감사합니다. 나는 $ ne를 인용하고 None을 사용하려고했으나 작동하지 않는다 ""service = db.logs.distinct ("service_description", { "service_description": { "$ ne": None}}) "이 오류가 발생했습니다"TypeError : distinct()는 정확히 2 개의 인수 (3이 주어진다.) " –
pymongo에서 인터페이스가 더 유창하기 때문이다. 'find () .distinct ()', cf.를 사용해야합니다. (문서) [http://api.mongodb.org/python/current/api/pymongo/collection.html?highlight=distinct#pymongo.collection.Collection.distinct] –
예를 들어 주시겠습니까? 나는 초보자입니다. 고마워 –