创建用户
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

待续。。。

MongoDB随笔的更多相关文章

  1. MongoDB随笔3:使用索引

    创建索引的语句很简单. 1.单键索引的创建:db.test.ensureIndex({name:1},{name:'index_name'}) 2.复合索引的创建:db.test.ensureInde ...

  2. [转]MongoDB随笔2:使用查询

    转自:http://www.cnblogs.com/yangecnu/archive/2011/07/16/2108450.html 一.通过查询获取数据 在深入讨论查询之前,首先来了解一下查询返回的 ...

  3. 【数据库】Redis/MongoDB/MySQL/Oracle随笔索引

    数据库体系 [思维导图]数据库体系 密码: a8ni Redis JPA

  4. linux环境下安装mongodb

    最近有用到mongodb,顺便找到了以前的指南,顺便写一篇随笔,以后或许有用到的地方. 第一步:下载mongodb的linux版本,mongodb-linux-x86_64-3.2.4.tgz(去官网 ...

  5. 通过MongoDB的samus驱动实现基本数据操作

    一.MongoDB的驱动 MongoDB支持多种语言的驱动: 在此我们只介绍 C# 的驱动.仅C#驱动都有很多种,每种驱动的形式大致相同,但是细节各有千秋,因此代码不能通用.比较常用的是官方驱动和sa ...

  6. 8天学通MongoDB

    随笔分类 - MongoDB 双十一来了,别让你的mongodb宕机了 摘要: 好久没过来吹牛了,前段时间一直赶项目,没有时间来更新博客,项目也终于赶完了,接下来就要面临双十一这场惊心动魄的处女秀考验 ...

  7. 如何在.Net中使用MongoDB

    最近在研究mongodb,针对.net 中使用mongodb的文章要么是早期的驱动版本,要么资料很少,所以写个随笔记录一下 本文主要记录 1.什么是MongoDB 2.MongoDB windows ...

  8. MongoDB入门系列(一):基础概念和安装

    概述 MongoDB是目前非常流行的一种非关系型数据库,作为入门系列的第一篇本篇文章主要介绍Mongdb的基础概念知识包括命名规则.数据类型.功能以及安装等. 环境: OS:Windows Versi ...

  9. MongoDB入门系列(二):Insert、Update、Delete、Drop

    概述 本章节介绍Insert.Update.Delete.Drop操作基本语法. 环境: Version:3.4 insert insert()基本语法如下: db.collection.insert ...

随机推荐

  1. 通过完整示例来理解如何使用 epoll

    网络服务器通常使用一个独立的进程或线程来实现每个连接.由于高性能应用程序需要同时处理大量的客户端,这种方法就不太好用了,因为资源占用和上下文切换时间等因素影响了同时处理大量客户端的能力.另一种方法是在 ...

  2. Ripple 水波纹效果

    背景+波纹 对于有边界限制的Ripple,我们就需要给他提供一个范围,即添加一个item标签. 如果在一个ripple标签中,添加一个item标签,在item中添加如下属性: [android:dra ...

  3. XMPPFrameWork IOS 开发(三)登录

    原始地址:XMPPFrameWork IOS 开发(三) XMPP中常用对象们: XMPPStream:xmpp基础服务类 XMPPRoster:好友列表类 XMPPRosterCoreDataSto ...

  4. Thinkphp学习笔记6-redirect 页面重定向

    ThinkPHP redirect 方法可以实现页面的重定向(跳转)功能.redirect 方法语法如下: $this->redirect(string url, array params, i ...

  5. 【问题】VH

      [问题]: CSS中使用了VH,在iOS中展示正常,但是在安卓的个别浏览器中,当输入框弹出时,使用VH的DIV的高度会发生变化. [原因]: 在安卓端浏览器虚拟键盘弹出时,导致视口高度改变,以至于 ...

  6. [Webpack] Create Separate webpack Configs for Development and Production with webpack-merge

    The development and production modes in webpack optimize the output in different ways. In developmen ...

  7. [Angular-Scaled web] 5. ui-router $stateParams for sharing information

    When using ui-route, we want to pass the information with the url. Example: angular.module('categori ...

  8. linux free命令详解和使用实例(查看内存使用率)

    转载:http://www.jb51.net/LINUXjishu/152017.html 1.命令格式: free [参数] 2.命令功能: free 命令显示系统使用和空闲的内存情况,包括物理内存 ...

  9. vue mixin使用

    1.概述 将一些公用方法引入到不同的组件中. 2.引入方式 (1)全局引入 // 注册全局Mixin Vue.mixin({ methods: { $touch: function() { // 用以 ...

  10. js&jquery获取指定table指定行里面的内容

      js&jquery获取指定table指定行里面的内容 CreateTime--2018年5月18日11:46:04 Author:Marydon 1.展示 代码展示 <table s ...