Mongodb 3.0 index and set daily operations, mongodb3.0
----- 1. create an index 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 has been downgraded to db. tblorders. ensureIndex ({"OrderNo": 1}, {background: true, name: "index_OrderNo"}); db. orderlog. ensureIndex ({"OrderNo": 1}, {background: true, name: "index_orderlog"}); ----- 2. query existing index Syntax:> 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. query index size Syntax:> db. tblorders. totalIndexSize () e ---- 4. the object is renamed use admin; db. runCommand ({renameCollection: "jinrilog. orderlog201508 ", to:" jinrilog. orderlog ", dropTarget: false}); ----- 5. delete the index database. tblorders. dropIndexes (); ----- 6. delete an object -- Method 1:> db. tblorders. drop (); true> db. tblorders. find (). count (); 0> show tables; hisorderst1> --- Method 2: db. tblorders. remove ({}); db. collection. drop () # is used to delete a data set from the database, including index db. collection. remove () # delete all documents from a collection, delete all documents matching one condition, or delete only one document one by one. --- 7. kill session> db. currentOp () {"inprog": [{"desc": "conn189", "threadId": "0x3e083380", "connectionId": 189, "opid": 953531, -- process 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 "}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.