mongoexport
mongoexport用于导出数据,-q是query, -f是fields的含义,多个fields用,隔开
mongoexport -h 127.0.0.1 --port 27000 -d hookHeroes -c pvp -q '{}' -f score,power -o res.csv
mongo操纵数组
删除数组元素
<pre>
>db.guild.find({"_id":2},{"vp":1});
{ "_id" : 2, "vp" : [ 13331, 10012, 10279, 10278, 10177 ] }
db.guild.update({"_id":2},{$pull:{'vp':NumberInt(10012)}});
> db.guild.find({"_id":2},{"vp":1});
{ "_id" : 2, "vp" : [ 13331, 10279, 10278, 10177 ] }
</pre>
添加数组元素
<pre>
db.guild.update({"_id":2},{$push:{'vp':NumberInt(10287)}});
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
db.guild.find({"_id":2},{"vp":1});
{ "_id" : 2, "vp" : [ 13331, 10279, 10278, 10177, 10287 ] }
</pre>
set用法
<pre>
db.users.update({"_id":58380945},{$set:{"account":"MCSMOKEY@gmail.com","password":"e10adc3949ba59abbe56e057f20f883e","is_formal":NumberInt(1)}});
db.getCollection('item').update({},{'$set':{'material':"面料成分说明"}},false,true)
</pre>
unset用法
<pre>
db.getCollection('item').update({},{'$unset':{'marterial':1}},false,true)
</pre>
创建索引
<pre>
db.userInfo.createIndex( { "trial.stage_id": -1,"trial.pass_time":1});
</pre>
删除索引
<pre>
db.userInfo.dropIndex( { "trial.stage_id": -1,"trial.pass_time":1});
</pre>
获取索引
<pre>
db.userInfo.getIndexes();
</pre>
查看执行计划
<pre>
db.userInfo.find().sort({"trial.stage_id":-1,"trial.pass_time":1}).limit(1).explain("executionStats");
</pre>
sort使用
<pre>
db.guild.find().sort({"_id":-1}).limit(1)
</pre>
查询某个字段不存在的document
<pre>
db.guild.find({"name":null})
</pre>
and的用法和匹配数组中某一项的用法
<pre>
db.bag.find({$and:[{"_id":33013},{"equip.eid":1414}]});
</pre>
db.userInfo.update({"_id":10436},{$set:{"buy_limits":[{"id":NumberInt(4),"type":NumberInt(1),"count":NumberInt(0)}]}});
竞技场清空战斗纪录
<pre>
db.getCollection('arena').update({},{'$set':{'logs':[]}},{upsert:false,multi:true})
</pre>
网友评论