创建用户
db.createUser({user: "abc",pwd: "abc123",roles: [ { role: "readWrite", db: "test" } ]});
db.system.users.remove({user:"abc"})
 
MongoDB导出数据
mongoexport -d service -c speech -o file --type csv -f id,time
mongoexport -d service -c speech -o file --type json -f id,time
 
mongoexport -d service -c speech -o file.json --type json -f id,time -q '{"time": {$gt:1483200000000}}' #大于等于2017年
mongoexport -d service -c speech -o file.csv --type csv -f id,time -q '{"time": {$gt:1483200000000}}' #大于等于2017年
 

建立全文索引
db.imooc_collections.ensureIndex({article:"text"})
db.imooc_collections.ensureIndex({"$**":"text"})

db.imooc_collections.find({$text: {$search: "aa"}})
db.imooc_collections.find({$text: {$search: "aa bb cc"}}) 或查询
db.imooc_collections.find({$text: {$search: "aa bb -cc"}}) 排除cc查询
db.imooc_collections.find({$text: {$search: "\"aa\" \"bb\" \"cc\"}}) 且查询

相似度排序
db.imooc_collections.find({$text: {$search: "aa bb"},{score: {$meta: "textScore"}}})
db.imooc_collections.find({$text: {$search: "aa bb"},{score: {$meta: "textScore"}}}).sort({score: {$meta: "textScore"})

MongoDB更新字段及其子字段

collection.update({'account_id': field[0].strip()}, {"$set":{'account_id': field[1].strip(), "waibu":"waibu2", "person_info.account_id": field[1].strip()}},False,True)

数据源为:

{
"_id" : ObjectId("591dc17c10a5664726235e70"),
"account_id" : "5A76F4CAFD5771C98659D6982DA34BF0",
"waibu" : "waibu2",
"person_info" : {
"account_id" : "5A76F4CAFD5771C98659D6982DA34BF0",
"test" : "abc"
}
}

MongoDB实现groupby count操作

db.l2.aggregate([{$group : {_id : "$account_id", num_tutorial : {$sum : }}}])

MongoDB实现groupby avg操作

db.speech.aggregate([{$group:{_id:"$domain",avger:{$avg:"$time"}}}])

MongoDB实现单字段分段查询:

db.client_agent.find({"time":{'$gte':,'$lt':}}).count()

MongoDB实现and操作

db.speech.find({"$and":[{"time":{'$gte':,'$lt':}},{"province":"西藏"}]}).pretty().count()

MongoDB实现distinct操作

db.speech.distinct('city',{"time":{"$gte":}})

MongoDB实现count(distinct city)操作

db.runCommand({"distinct":"speech","key":"city","query":{"time":{"$gte":}}}).values.length

待续。。。

最新文章

  1. Wave - 花たん 音乐
  2. UEditor 1.4.3.1.NET版本上传配置备忘录
  3. noj[1581] 筷子
  4. java 练手 Fibonacci数
  5. hdu2476 String painter(区间dp)
  6. Java常用快捷键
  7. jQuery异步分页插件
  8. MYSQL根据分类分组取每组一条数据且按条件能排序的写法
  9. 9月mob(ShareSDK)活动预告,这个秋天非常热
  10. C#第十一天(winform)
  11. 利用XShell上传、下载文件(使用sz与rz命令),超实用!
  12. java.util.Date 与 java.sql.Date 之间的转换
  13. 在Asp.Net MVC中使用Repeater控件
  14. 04-cookies 会话跟踪技术
  15. css快速入门-引入方式
  16. python3 中文乱码,UnicodeEncodeError: 'latin-1' codec can't encode characters in position 10-13: ordinal not in range(256)
  17. 禁止Apache显示目录索引的常见方法
  18. Luogu 4724 三维凸包
  19. hdu1010Tempter of the Bone(迷宫dfs+剪枝)
  20. 随机获取图片的api接口

热门文章

  1. [置顶] OpenJDK源码研究笔记(九)-可恨却又可亲的的异常(NullPointerException)
  2. Converting a fisheye image into a panoramic, spherical or perspective projection [转]
  3. SQL VM上磁盘延迟高, 但Host和Storage Array上的延迟却很低的问题
  4. hadoop压缩框架
  5. [Python爬虫] 之三十一:Selenium +phantomjs 利用 pyquery抓取消费主张信息
  6. ActiveReport开发入门-列表的交互性
  7. KRBTabControl(中文)Windows选项卡控件
  8. [Angular-Scaled web] 4. Using ui-router's named views
  9. 2014年七月最佳jQuery插件荟萃
  10. T-SQL 之 存储过程