我想使用 python 脚本创建数据库和集合,以便使用 pymongo 驱动程序。但我无法创建数据库。
我遵循的步骤:
from pymongo import MongoClient
con = MongoClient('localhost', 27017)
db = con.testdb
在执行此命令后,当我签入 mongoshell 时,不会创建数据库“testdb”。
我可以使用 paramiko 与 mongo shell 交互吗?
蟒蛇版本:2.7
答案1
从http://api.mongodb.com/python/current/tutorial.html
它指出
An important note about collections (and databases) in MongoDB is that
they are created lazily - none of the above commands have actually
performed any operations on the MongoDB server. **Collections and
databases are created when the first document is inserted into them.**