To install MongoDB self-search, I offer here a GUI version similar to Navicat.
1. Database level
Show DBS #查看服务器上的数据库 [local 0.000GB]
Use test #切换到指定数据库 if test does not exist in the database, the test database will be created
DB #查看当前数据库 [test]
Db.dropdatabase () #删除当前使用的数据库 [{"Dropped": "Test", "OK": 1}]
2. Collection level
Db.createcollection ("book") #新建一个名叫book的collection
Show Collections #查看当前数据库中的所有集合
Db.book.drop () #删除名叫book的collection
Db.book.renameCollection ("Book2") #将book renamed to Book2
Db.book.ensureIndex ({id:1}) #在book集合上, establish an index to the ID field, 1 for ascending
Db.book.getIndexes () #获取book集合上的索引
Db.book.dropIndex ({id:1}) #删除book集合上的索引
=============db.collection.update (criteria, objnew, Upsert, Multi) ======
Update () parameter description:
The criteria:update query condition is equivalent to the WHERE Condition clause in SQL update
Objnew: updated object and some update operations, can be understood as set column= ' value '
Upsert: If no record of update is present, insert objnew True to insert, false does not insert
Multi:mongodb default False, update only the first record found, if this parameter is true, you can find out all the records are updated by criteria
========================================================================
Db.book.update ({},{$rename: {"BookName": "Bookname2"}},false,true) #将book集合中的所有记录的bookname字段的名字修改为bookname2
Db.book.update ({},{$set: {"Price", "}},false,true") #为book集合的每一条记录添加一个字段, and assigned a value of 50
Db.book.update ({},{"$unset": {"price": 1}},false,true) #删除集合中的所有记录的price字段
Db.book.insert ({"BookName": "Introduction to Algorithms", "Price": ""} ") #向book集合中插入两条记录
Db.book.save ({"Bookename": "Data Structure", "Price": "$"}) #和insert一样也能插入一条记录
Db.book.find () #查询出book集合中所有的记录数
[email protected] Getting started one