问题
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