mongo操作备忘

Posted dribs

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mongo操作备忘相关的知识,希望对你有一定的参考价值。

#查看collection内 某个字段条目数
db.dictionary_system.find({"name":"xxx"}).count()
#清空某个collection的字段,很危险,很危险,很危险,不要执行,不要执行,不要执行!!!!他会把有name的都干掉!!!!删除用下面的remove
db.dictionary_system.update({},{$unset:{‘name‘:‘xxx.xxx‘}},false, true)
#查看某个字段在collection的内容
db.dictionary_system.find({"name":"xxxx"})
#备份某个collection
mongoexport -h xxxxxxx.mongodb.rds.aliyuncs.com:3717 -uxxxx -d xx-c dxxxxx  -o xxxxx
#导入整个collection。导入失败
mongoimport -hdds-2ze641e07cb38e441.mongodb.rds.aliyuncs.com:3717 -dhalo -cdictionary_system -unlpuser  dictionary_system.mongo
#通过某个json导入
mongoimport  --host xxxxxmongodb.rds.aliyuncs.com:3717 -uxxxxx -pxxxxx -dhalo -cxxxxx --file xxxx.json
#按照id删除某个collections
db.xxxxx.remove({"_id":ObjectId("xxxxx")});

  

采坑不小心百度出来unset的方式删除某条字段,结果悲剧了,都你妈删了,望后来者不要使用update  unset  去删除某个mongo的collection字段,他会把符合key的都干掉,而不管value

以上是关于mongo操作备忘的主要内容,如果未能解决你的问题,请参考以下文章

备忘Idea的那些事

Jacoco和Tycho surefire的Eclipse RCP插件代码介绍

Eclipse 中的通用代码片段或模板

xml Eclipse模板(代码片段)检查参数并最终抛出IllegalArgumentException

spring练习,在Eclipse搭建的Spring开发环境中,使用set注入方式,实现对象的依赖关系,通过ClassPathXmlApplicationContext实体类获取Bean对象(代码片段

常用python日期日志获取内容循环的代码片段