Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mongo statement accumulation

2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report