我已使用PyMongo将几个文档插入到名为“ cards”的集合中,并且在运行该Python应用程序时它确实会返回结果。
import pprint
import pymongo
from pymongo import MongoClient
import scrython
client = MongoClient()
db = client.mtg
collection = db.cards
posts = collection
example_card_2 = { "card_name" : "Example Card Name 2",
"mana_cost" : ["Blue", "Red", "Black"],
"card_rarity" : "rare",
"card_text" : "This is an example card that does other stuff",
"card_attributes" : ["Vigilance","Menace"],
"atk_def": "5 / 5"}
post_id = posts.insert_one(example_card_2).inserted_id
for x in posts.find():print(x)
当我在MongoDBs外壳中导航到该集合并运行以下命令时,没有返回结果:
db.cards.findOne()
db.cards.find()
有趣的是,当我从MongoDB Shell中插入文档时,在Shell中运行搜索时会显示该文档,因此此处出现问题。该集合最初是从我的PyMongo应用程序创建的,因此我没有理由相信它们是两个不同的实体。
关于这里发生的事情有什么想法吗? *编辑:如下所述,当我键入“使用卡片”时,实际上确实创建了一个名为“卡片”的数据库,这就是我要搜索的地方。键入 use mtg ,然后键入 db.cards.findOne()时,我得到了预期的结果。