![pymongo를 사용하여 새 데이터베이스와 컬렉션을 만드는 방법은 무엇입니까?](https://linux55.com/image/130618/pymongo%EB%A5%BC%20%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC%20%EC%83%88%20%EB%8D%B0%EC%9D%B4%ED%84%B0%EB%B2%A0%EC%9D%B4%EC%8A%A4%EC%99%80%20%EC%BB%AC%EB%A0%89%EC%85%98%EC%9D%84%20%EB%A7%8C%EB%93%9C%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%80%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F.png)
Python 스크립트를 사용하여 pymongo 드라이버를 사용하기 위한 데이터베이스와 컬렉션을 만들고 싶습니다. 하지만 데이터베이스를 만들 수는 없습니다.
내가 따랐던 단계:
from pymongo import MongoClient
con = MongoClient('localhost', 27017)
db = con.testdb
이 명령을 실행한 후 mongoshell을 체크인하면 "testdb" 데이터베이스가 생성되지 않습니다.
paramiko를 사용하여 mongo 셸과 상호 작용할 수 있나요?
파이썬 버전: 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.**