Pymongo importing succeeded but not showing in the collection

筅森魡賤 提交于 2019-12-25 10:02:10

问题


I tried importing json file which succeeded

mongoimport --db dbwhy --collection dbcol --jsonArray consumer_complaint.json
2016-01-15T19:00:42.277-0600    connected to: localhost
2016-01-15T19:00:42.320-0600    imported 34 documents

but when I tried viewing it, it was not there

from pymongo import MongoClient

client = MongoClient('localhost',27017)
db = client['dbwhy']
coll = db['dbcol']
curs = db.coll.find()
for i in curs:
    print(i)

It does not show anything


回答1:


The problem is here:

db.coll.find()

This would find all documents inside the coll collection, but your collection is named dbcol.

Instead, use the coll variable that you've already defined:

from pymongo import MongoClient

client = MongoClient('localhost',27017)

db = client['dbwhy']
coll = db['dbcol']

curs = coll.find()  # FIX is here
for i in curs:
    print(i)


来源:https://stackoverflow.com/questions/34822568/pymongo-importing-succeeded-but-not-showing-in-the-collection

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!