我尝试导入成功的json文件
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
但是当我尝试查看时,它不存在
from pymongo import MongoClient
client = MongoClient('localhost',27017)
db = client['dbwhy']
coll = db['dbcol']
curs = db.coll.find()
for i in curs:
print(i)
它没有显示任何内容
答案 0 :(得分:1)
问题在于:
db.coll.find()
这会找到 coll
集合中的所有文档,但您的集合名为dbcol
。
相反,请使用您已定义的coll
变量:
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)