我无法使用python从mongodb获取数据

问题描述 投票:0回答:1

这是下面的代码:

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中,但是在检索相同的数据时,此代码显示此错误,请提供帮助。

python-3.x
1个回答
0
投票
您将获得一个游标对象,只需对其进行迭代。您会找到相关记录。详细信息= collection.find({“ intent”:“ patterns”})有关详细数据:打印(数据)
© www.soinside.com 2019 - 2024. All rights reserved.