在安裝MongoDB后,啟動服務(wù)器進(jìn)程(mongod),可以通過在客戶端命令mongo實現(xiàn)對MongoDB的管理和監(jiān)控:

這是MongoDB最上層的命令列表,主要是管理數(shù)據(jù)庫的:數(shù)據(jù)庫操作幫助、集合操作幫助、管理幫助。如果想了解數(shù)據(jù)庫操作更詳細(xì)的命令,可以直接使用db.help(),如下所示:

use yourDBshow dbsdb.dropDatabase()db.cloneDatabase("127.0.0.1")db.copyDatabase("mydb","temp","127.0.0.1")db.repairDatabase()db.getName或dbdb.stats()db.version()db.getMongo()  db.createCollection('collName',{size:20,capped:5,max:100}) 創(chuàng)建成功會顯示{"ok":1}db.getCollection("account")db.getCollectionNames()db.PRintCollectionStats()db.addUser("name")和db.addUser("userName","pwd123",true) 設(shè)置密碼、是否只讀db.auth("userName","123123")show usersdb.removeUser("userName")db.userInfo.find() 默認(rèn)每頁顯示20條記錄db.userInfo.disinct("name")db.userInfo.find({"gae":22}) 查詢age==22的集合db.userInfo.find({"age":{$gt:22}})db.userInfo.find({"age":{$lt:22}})  db.userInfo.find({name:/mongo/})db.userInfo.find({name:/^mongo/})db.userInfo.find({},{name:1,age:1})db.userInfo.find({age:{$gt25}},{name:1,age:1})db.userInfo.find().sort({age:1})db.userInfo.find().limit(5)db.userInfo.find().skip(10)db.userInfo.find().limit(10).skip(5)db.userInfo.find({$or:[{age:22},{age:25}]})db.userInfo.findOne()db.userInfo.find().count()db..find({sex:{$exists:true}}).count()1.key: 這個就是分組的key 2.initial: 每組都分享一個初始化函數(shù),特別注意:是每一組initial函數(shù)。 3.reduce: 這個函數(shù)的第一個參數(shù)是當(dāng)前的文檔對象,第二個參數(shù)是上一次function操作的累計對象。有多少個文檔, $reduce就會調(diào)用多少次。 4.condition: 這個就是過濾條件。 5.finalize: 這是個函數(shù),每一組文檔執(zhí)行完后,多會觸發(fā)此方法。
新聞熱點
疑難解答