mongodb 3.0 索引和集合日常操作,mongodb3.0

來源:互聯網
上載者:User

mongodb 3.0 索引和集合日常操作,mongodb3.0

-----1.建立索引db.tblorders.dropIndexes();db.tblorders.createIndex( { "OrderNo" : 1 },{background:true, name:"index_OrderNo"} );db.hisorders.createIndex( { "orderno" : 1 },{background:true, name:"hisorders_index_orderno"} );--ensureIndex已經降級db.tblorders.ensureIndex({"OrderNo" : 1},{background:true, name:"index_OrderNo"});db.orderlog.ensureIndex({"OrderNo":1},{background:true, name:"index_orderlog"});-----2.查詢已有索引文法:> db.tblorders.getIndexes()db.hisorders.getIndexes()db.tblorders.find({OrderNo:"A2022823590918802334"}).forEach(printjson);db.tblorders.find({OrderNo:"20130901010019880500"}).forEach(printjson);db.tblorders.find({OrderNo:"A2013090106022059954"}).forEach(printjson);db.tblorders.find({OrderNo:"H2013090103019884364"}).explain("executionStats");db.tblorders.find({OrderNo:"H2013090103019884364"}).explain("executionStats");-----3. 查詢索引大小文法:>  db.tblorders.totalIndexSize()e----4.對象改名use admin;db.runCommand({renameCollection:"jinrilog.orderlog201508",to: "jinrilog.orderlog",dropTarget: false});-----5.刪除索引db.tblorders.dropIndexes();-----6.刪除對象--方法1:> db.tblorders.drop() ;true> db.tblorders.find().count();0> show tables;hisorderst1> ---方法2:db.tblorders.remove( { } );db.collection.drop()    #是用來從資料庫中刪除一個資料集合包括索引db.collection.remove()#可以從一個集合中刪除所有文檔,刪除匹配一個條件的所有文檔,或者限制操作只刪除一條文檔,逐條刪除.---7.kill session> db.currentOp(){"inprog" : [{"desc" : "conn189","threadId" : "0x3e083380","connectionId" : 189,"opid" : 953531,  --進程ID"active" : true,"secs_running" : 852,"microsecs_running" : NumberLong(852352681),"op" : "remove","ns" : "jinri.tblorders","query" : {},"client" : "192.168.0.180:46773","numYields" : 148618,"locks" : {"Global" : "w","Database" : "w","Collection" : "w"},"waitingForLock" : false,"lockStats" : {"Global" : {"acquireCount" : {"r" : NumberLong(148619),"w" : NumberLong(148619)}},"Database" : {"acquireCount" : {"w" : NumberLong(148619)},"acquireWaitCount" : {"w" : NumberLong(3)},"timeAcquiringMicros" : {"w" : NumberLong(388)}},"Collection" : {"acquireCount" : {"w" : NumberLong(148619)}}}}]}> db.killOP(953531){ "info" : "attempting to kill op" }


著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.