Get the App
SLTechnology News&Howtos  ›  Database  › 

Mongo statement accumulation

Shulou Source: shulou.com Published: 2022-06-01 11:31:22 10月26日 Update

Db.collection.stat ()-View table results

Db.collection.find ({ipad:/ ^ 10.42 / {) .pretty ()-View the IPAD field of IPAD that starts with 10.42 (ends with 10.42 $)

Db.collection.find ({ipad:/ ^ 10.42 /}, {vipad:1.ipad:1,id:0})-the first {condition}, non-id field: 1 (display), _ id:0 (not shown)

Db.collection.find () .limit (n)-limits the output of several rows of records

Db.collection.find ({"aa": {"$nin": [PDB,CDB]}})-conditions for querying related fields not in

Db.collection.find ({aa.sid: "cdb01"})-aa field is a [collection of small documents]-[sid: "cdb01", hostname: ""....]

Db.collection.remove ({ipad:/ ^ 10.42 /})-delete specific condition records, delete all without conditions

Db.collection.drop ()-delete the entire document collection

Db.vipad.renameCollection (vipad1)-the table name has been changed from VIPAD to VIPAD1

Db.collection.update ({ipad:/ ^ 10.42 /}, {$set: {isUser: "true"}}, {multi:true})-update the value of the field isuser according to the condition. Multi:true means that all records that meet the condition are updated. The first entry is updated without this parameter value by default.

Db.getCollection ('vipad') .update ({}, {$rename: {"dg01": "dg02"}}, {multi:true})

-multi:true adds fields to the entire table, of course, it can also be written as false,true.

Db.vipad.update ({}, {$set: {aa: ""}}, false,true)-added the field aa, which is empty by default. Instead, delete the field with $unset.

Db.aaa.distinct ("nmid", {"class": 3})-- remove weight

DBQuery.shellBatchSize = 100;-type it for more setting

Batch update: version: "8.7-abc"-update to version: "8.7"

Var collection = 'test';// collection name

Var cnt=0

DB [collection]. Find (). ForEach (function (doc) {

DB [collection] .update ({_ id:doc._id}

{$set: {version:doc.version.replace (/-abc$/,'')}}, false,true)

Cnt=cnt+1

});

Print (cnt)

Tags: Fields conditions updates documents representatives parameters beginning results queries output restrictions statements accumulation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Docker vpn Shulou Tech Info OPPO Reno