这是下面的代码:
import sys
from pymongo import MongoClient
import json
def main ():
# Connection to the MongoDB Server
mongoClient = MongoClient ('localhost:27017')
# Connection to the database
db = mongoClient.Botdata
Botdata = db.Botdata
collection = db.intent
details = collection.find ({"intents": "patterns"})
#docs = list(Botdata.find({'intents': 'tag'}))
print(details)
if __name__ == "__main__":
main ()
主要问题是,每当我运行此代码时,都会出现此类错误:
<pymongo.cursor.Cursor object at 0x7f31623955f8>
问题是我已经将数据存储在mongodb中,但是在检索相同的数据时,此代码显示此错误,请帮忙。
答案 0 :(得分:1)
您将获得一个游标对象,只是对其进行迭代。您会找到相关记录。
details = collection.find ({"intents": "patterns"})
for data in details:
print(data)