pymongoを使用して新しいデータベースとコレクションを作成するには?

pymongoを使用して新しいデータベースとコレクションを作成するには?

Pythonスクリプトを使用してpymongoドライバを使用するためのデータベースとコレクションを作成したいと思います。しかし、データベースを作成することはできません。

私が従ったステップ:

from pymongo import MongoClient
con = MongoClient('localhost', 27017)
db = con.testdb

このコマンドを実行した後にmongoshellをチェックインすると、「testdb」データベースは作成されません。

paramikoを使ってmongoシェルとやり取りできますか?

Pythonバージョン: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.**

おすすめ記事