【发布时间】:2016-11-18 22:32:00
【问题描述】:
import pymongo
uri = 'mongodb://127.0.0.1:27017'
client = pymongo.MongoClient(uri)
db = client.TeamCity
students = db.students.find({})
for student in students:
print (student)
Python 结果:
空白
MongoDB:结果
db.students.find({})
{ "_id" : ObjectId("5788483d0e5b9ea516d4b66c"), "name" : "Jose", "mark" : 99 }
{ "_id" : ObjectId("57884cb3f7edc1fd01c3511e"), "name" : "Jordan", "mark" : 100
}
import pymongo
uri = 'mongodb://127.0.0.1:27017'
client = pymongo.MongoClient(uri)
db = client.TeamCity
students = db.students.find({})
print (students.count())
Python 结果:
0
mongoDB 结果
db.students.find({}).count()
2
我错过了什么?
对于
import pymongo
uri = 'mongodb://127.0.0.1:27017'
client = pymongo.MongoClient(uri)
db = client.TeamCity
students = db.students.find({})
print (students)
Python 结果:
所以我认为它能够成功连接到数据库但没有返回结果
【问题讨论】:
-
能否在 mongoDB shell 中显示你的数据库名称,即命令 'db' 的输出
-
> 显示 dbs Teamcity 0.000GB 本地 0.000GB