基本概念

数据库名全部小写
MongoDB区分类型和大小写(包括函数)
field名字不能有 “."/"null"(空格),不能以"$"开头
以下划线"_"开头的键是保留的(不是严格要求的)
文档的键是字符串
集合名不能以"system."开头,这是为系统集合保留的前缀

可视化管理工具

https://docs.mongodb.com/ecosystem/tools/administration-interfaces/
再linux上不要使用robomongo,数据量较大时没法完整读取
推荐使用mongochef:http://3t.io/mongochef/download/core/platform/#tab-id-3

b.system.* 包含多种系统信息的特殊集合(Collection)

集合命名空间 描述
db.system.namespaces 列出所有名字空间。
db.system.indexes 列出所有索引。
db.system.profile 包含数据库概要(profile)信息。
db.system.users 列出所有可访问数据库的用户。
db.local.sources 包含复制对端(slave)的服务器信息和状态

Import Example Dataset

获得数据例子
Import data into the collection

mongoimport --db test --collection restaurants --drop --file ~/downloads/primer-dataset.json

注意:
The mongoimport connects to a mongod instance running on localhost on port number 27017. The --file option provides the path to the data to import, in this case, ~/downloads/primer-dataset.json.

To import data into a mongod instance running on a different host or port, specify the hostname or port by including the --host and the --port options in your mongoimport comman

document

一些限制

如Maximun index key length

嵌入文档Embedded Documents

{...name: { first: "Alan", last: "Turing" },contact: { phone: { type: "cell", number: "111-222-3333" } },...
}

访问number:contact.phone.number

document field order

Starting in version 2.6, MongoDB actively attempts to preserve the field order in a document. Before version 2.6, MongoDB did not actively preserve the order of the fields in a document

_id field

The _id field has the following behavior and constraints:

  • By default, MongoDB creates a unique index on the _id field during the creation of a collection.
  • The _id field is always the first field in the documents. If the server receives a document that does not have the _id field first, then the server will move the field to the beginning.
  • The _id field may contain values of any BSON data type, other than an array.

Query Filter documents

specify the conditions that determine which records to select for read, update, and delete operations

{<field1>: <value1>,<field2>: { <operator>: <value> },...
}

Update Specification Documents

{<operator1>: { <field1>: <value1>, ... },<operator2>: { <field2>: <value2>, ... },...
}

Bson types

可以使用$type操作符
Type Number Alias Notes
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”

ObjectId

consists of 12-bytes, where the first four bytes are a timestamp that reflect the ObjectId’s creation, specifically

a 4-byte value representing the seconds since the Unix epoch,
a 3-byte machine identifier,
a 2-byte process id, and
a 3-byte counter, starting with a random value.

转载于:https://www.cnblogs.com/jcuan/p/5693621.html

mongodb笔记 getting started相关推荐

  1. MongoDB笔记---路遇超多坑

    MongoDB笔记-路遇超多坑 Mac安装MongoDB时需要关闭本机SIP 终端执行 csrutil status ---检查SIP是否开启 System.....:enabled 开启状态 当文件 ...

  2. MongoDB笔记记录(雷哥课堂)–基本命令

    MongoDB笔记记录(雷哥课堂)–基本命令 3 常用命令 3.1 数据库操作 3.1.1 选择和创建数据库 use 数据库名称 如果数据库不存在就自动创建,如果存在则选择该数据库 以下数据库名是保留 ...

  3. mongodb笔记(三)

    1.删除文档(remove()函数) 在执行remove()函数前先执行find()命令来判断执行的条件是否正确,这是一个比较好的习惯. 语法: db.collection.remove(<qu ...

  4. YII2操作mongodb笔记

    2019独角兽企业重金招聘Python工程师标准>>> 操作之前得保证已经安装了mongodb,windows下安装可参考另一篇博文: http://my.oschina.net/c ...

  5. Mongodb 笔记04 特殊索引和集合、聚合、应用程序设计

    特殊索引和集合 1. 固定集合:固定集合需要事先创建好看,而且它的大小是固定的.当固定集合被占满时,如果再插入新文档,固定集合会自动将最老的文档从集合中删除. 2. 创建固定集合:db.createC ...

  6. YII2操作mongodb笔记(转)

    componets配置: 'mongodb' => ['class' => '\yii\mongodb\Connection','dsn' => 'mongodb://test:12 ...

  7. Mongodb 笔记01 MongoDB 简介、MongoDB基础知识、启动和停止MongoDB

    MongoDB 简介 1. 易于使用:没有固定的模式,根据需要添加和删除字段更加容易 2. 易于扩展:MongoDB的设计采用横向扩展.面向文档的数据模型使它能很容易的再多台服务器之间进行分割.自动处 ...

  8. mongodb笔记2

    成功启动MongoDB后,再打开一个命令行窗口输入mongo,就可以进行数据库的一些操作. 输入help可以看到基本操作命令: show dbs:显示数据库列表 show collections:显示 ...

  9. Mongodb笔记(三)user aggregate mapReduce

    版本:mongodb3.4. User: mongodb使用验证登录:默认不开启,mongod中使用--auth开启:  mongod -port=3000 --auth  : 基本方法: db.cr ...

  10. MongoDB笔记 -- ReplicationSet复制集

    文章目录 环境初定 搭建过程 现象观察 环境初定 MongoDB安装过程参考:https://blog.csdn.net/weixin_42480750/article/details/1089021 ...

最新文章

  1. 导航条——收缩式导航菜单
  2. 老鸟谈画图能力对运维人员的重要性
  3. angular 路由页面不刷新
  4. jdbc连接各种数据库方式列表
  5. 8.霍夫变换:线条——基本的霍夫变换算法、霍夫变换的复杂性、霍夫例子_3
  6. linux 解压文件zip格式
  7. android webview 文件下载,Android编程使用WebView实现文件下载功能的两种方法
  8. CorelDRAW零基础入门到精通
  9. 程序员如何编写高大上且实用的技术文档
  10. unity商店demo学习:跑酷游戏
  11. PPPOE拨号下MTU设置
  12. Minecraft mod制作简易教程(五)——本地化和国际化
  13. 每日一题——有效的数独
  14. CentOS7里ping命令详解
  15. 电子入门基础知识之:多路选择开关(MUX)
  16. 海思开发板实用技巧集
  17. Android代码中实现WAP方式联网
  18. 【各种转换】数组转换成字符串,集合转换成字符串,字符串转集合
  19. pytorch runtime error(59):device-side assert triggered at XXX
  20. [尚硅谷22版shiro]学习笔记

热门文章

  1. linux安装包安装nginx,Linux tar包安装Nginx
  2. pip:你真的熟悉怎么用了吗?
  3. ps软件电脑版_安装PS/AI/CDR软件,电脑配置的怎样?
  4. mysql 向量写法_mysql – 你如何在Ruby中处理一个非常大的向量?
  5. python中stacked_栈式自动编码器(Stacked AutoEncoder)
  6. kettle 零基础快速入门(一)
  7. go标准库的学习-encoding/base64
  8. Linux内存分配小结--malloc、brk、mmap【转】
  9. mkdir命令的-p和-m
  10. 初窥QuickTest脚本录制