1、Database对象,Collection对象
- 创建Connection对象
mongo(host:port)
如连接到本地主机的mongodb服务器,并创建一个Connection对象
var myConn = new Mongo("localhost");
- 创建Database对象:
>use test
>db.getName()
或者使用Connection对象的方法getDB()
mongo = new Mongo("localhost");
newDB = mongo.getDB("newDB");
newDB.getName();
- 创建Collection对象
//显示集合myCollection的统计信息
db.myCollection.stats()
或者使用Database对象的getCollection()
mycoll = db.getCollection("myCollection");
mycoll.stats();
2、管理数据库
- 显示数据库列表:
show dbs
- 切换到其他数据库:
use testDB
//或者
db = db.getSiblingDB('testDB');
- 创建数据库,添加集合或者用户时隐式创建
use newDB
db.createCollection("newCollection")
或者&#x