Getting Started with mongoDB Development

After starting the mongo shell your session will use the test database for context, by default. At any time issue the following operation at the mongo to report the current database:

db

db returns the name of the current database.

 

Step 1: From the mongo shell, display the list of databases with the following operation:

> show dbs

 

Step 2: Switch to a new database named mydb with the following operation:

> use mydb 

Note: At this point, if you issue the show dbs operation again, it will not include mydb, because mongoDB will not create a new database until you insert data into that database.

 

Step 3: Create a document, named j, with the following JavaScript operation:

> j = { name : "mongo" }

 

Step 4:  Insert the j document into the collection things with the following operation:

> db.things.insert(j)

Note: When you insert the first document, the mongod will create both the mydb database and the things collection. 

 

Step 5: Confirm that the collection named things exists using the following operation:

> show collections

 

Step 6: Confirm that the documents exist in the collection things by issuing quey on the things collection:

> db.things.find()

This operation returns the following results. The ObjectId values will be unique:

{ "_id" : ObjectId("515feca6f2d89963b39e5c08"), "name" : "mongo" }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值