getSiblingDB获取其余的数据库javascript
db.getCollection('xxx').find({"field_name":{"$lt":20000000}}).forEach(function(_item){ db.getSiblingDB("other_db").collection_name.update({"feild_name1":_item.field_name1},{$set:{"field_name2":_item.field_name2}},false,true); }) getSiblingDB("other_db")指定要跨的数据库 getSiblingDB("other_db").collection_name 指定表名collection_name
$elemMatch
匹配数据里的数据$set
更新java
db.getCollection('xxx').update({ "name":"bc2c2e9676e74600274d3e3738bab5c6a27dc85d560563b695fece08b6a7f7de", "array_name":{"$elemMatch":{"type":"control"}}, }, {"$set":{"array_name.$.amount":15000000}} )
db.集合名称.update({}, {$rename:{"旧键名称":"新键名称"}}, false, true) 第一个false表示:可选,这个参数的意思是,若是不存在update的记录,true为插入新的记录,默认是false,不插入。 第二个true表示:可选,mongodb 默认是false,只更新找到的第一条记录,若是这个参数为true,就把按条件查出来多条记录所有更新。
int转换成字符串类型 db.getCollection('xxx').find({"decimals":{$type:"int"}}).forEach(function(x){ x.decimals=String(x.decimals); db.asset.save(x); }) Double 1 “double” String 2 “string” Object 3 “object” Array 4 “array” Binary data 5 “binData” Undefined 6 “undefined” Deprecated. ObjectId 7 “objectId” Boolean 8 “bool” Date 9 “date” Null 10 “null” Regular Expression 11 “regex” DBPointer 12 “dbPointer” JavaScript 13 “javascript” Symbol 14 “symbol” JavaScript (with scope) 15 “javascriptWithScope” 32-bit integer 16 “int” Timestamp 17 “timestamp” 64-bit integer 18 “long” Min key -1 “minKey” Max key 127 “maxKey