一、新建/切換數據庫數據庫
> use testjson
use切換數據庫,若是數據庫不存在,則會建立這個數據庫,而且切換到此庫。spa
二、展現全部的數據庫code
>show dbsrem
或者:io
>show databasestable
三、展現所選數據庫下全部的表class
>show tablestest
或者:date
>show collections
四、查詢數據
>db.test.mongotest.find()
>db.test.mongotest.find().pretty() //json格式化結果
五、插入數據
>db.test.mongotest.insert({'name':'asif', 'age':18, 'sex':'男'})
六、更新數據
只更新第一條記錄:
db.col.update( { "count" : { $gt : 1 } } , { $set : { "test2" : "OK"} } );
所有更新:
db.col.update( { "count" : { $gt : 3 } } , { $set : { "test2" : "OK"} },false,true );
只添加第一條:
db.col.update( { "count" : { $gt : 4 } } , { $set : { "test5" : "OK"} },true,false );
所有添加加進去:
db.col.update( { "count" : { $gt : 5 } } , { $set : { "test5" : "OK"} },true,true );
所有更新:
db.col.update( { "count" : { $gt : 15 } } , { $inc : { "count" : 1} },false,true );
只更新第一條記錄:
db.col.update( { "count" : { $gt : 10 } } , { $inc : { "count" : 1} },false,false );
七、刪除數據
>db.test.mongotest.remove({'name':'HAHAHA', 'age':18, 'sex':'女'})