本文介绍了Pymongo 导入成功但未显示在集合中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试导入成功的 json 文件
mongoimport --db dbwhy --collection dbcol --jsonArray consumer_complaint.json2016-01-15T19:00:42.277-0600 连接到:本地主机2016-01-15T19:00:42.320-0600 导入 34 个文件
但是当我尝试查看它时,它不在那里
from pymongo import MongoClient客户端 = MongoClient('本地主机',27017)db = 客户端['dbwhy']coll = db['dbcol']诅咒 = db.coll.find()因为我在curs中:打印(一)
它没有显示任何东西
解决方案
问题出在这里:
db.coll.find()
这将找到 coll
集合中的所有文档,但您的集合名为 dbcol
.>
相反,使用您已经定义的 coll
变量:
from pymongo import MongoClient客户端 = MongoClient('本地主机',27017)db = 客户端['dbwhy']coll = db['dbcol']curs = coll.find() # FIX 在这里因为我在curs中:打印(一)
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
解决方案
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)
这篇关于Pymongo 导入成功但未显示在集合中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!