MongoDb 查询

 

如果要向所有集合中添加new_field,则必须使用空选择器,并将multi标志设置为true(最后一个参数)以更新所有文档

db.getCollection("tracked").update(
{},
{ $set: {"datas.FlightDetails":[] } },
false,
true
)

 

 

 

在上面的示例中,最后2个字段false, true指定upsert和multi标志。

Upsert: 如果设置为true,则在没有文档符合查询条件时创建一个新文档。

多个: 如果设置为true,则更新满足查询条件的多个文档。如果设置为false,则更新一个文档。

这是Mongo versions之前的2.2。对于最新版本,查询有所更改

db.your_collection.update({},

                          {$set : {"new_field":1}},

                          {upsert:false,

                          multi:true})

 

 

 

 


db.getCollection("Tags").find().limit(100);

db.getCollection("Tags").find().count();

--like 查询
db.getCollection("Tags").find({"Tag":{$regex:/htm1/}})

 

 

db.getCollection("queue").find({_id: ObjectId("6541f534c134a2616c0298da")});
db.getCollection("tracked").find({_id: ObjectId("6541f638c134a2616c0298db")});


db.getCollection("queue").find().count();

db.getCollection("queue").find().sort({"createTime":-1}).limit(100);

db.getCollection("queue").find({"assign":{$regex:"718hook"}}).sort({"resultTime":-1}).limit(100);

--like 查询
db.getCollection("queue").find({"assign":{$regex:"718hook"}}).limit(100);


db.getCollection("queue").find({"trackNums":{$in:[
"92001903380938366644409238",
"9214490289191406537660"
]}});

db.getCollection("tracked").find({"trackNums":{$in:[
"92001903380938366644409238",
"9214490289191406537660"
]}});

 

db.getCollection("queue").insert( {
_id: ObjectId("647eea2329e6d32b6bee5c81"),
count: NumberInt("0"),
createTime: "2023-06-06 16:11:15"

} );

 

posted @ 2023-11-22 18:16  cclon  阅读(16)  评论(0编辑  收藏  举报