mongodb笔记 getting started
2016-07-23 00:42
435 查看
基本概念
数据库名全部小写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
--hostand the
--portoptions 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.
相关文章推荐
- MongoDB基本命令用
- MongoDB 创建数据库
- MongoDB 创建数据库
- MongoDB 创建数据库
- MongoDB常用操作
- 28 个 MongoDB NoSQL 数据库的面试问答
- MySQL与MongoDB的区别
- MongoDB之Mtools工具
- centos安装node mongodb supervisor
- MongoDB C++ Driver 使用入门
- MongoDB 极简实践入门
- mongodb的安装
- mongodb操作
- OSX 安装MongoDB
- java操作MongoDB数据库
- java操作MongoDB数据库
- MongoDB助力快速搭建物流订单系统
- mongodb 监听远程连接
- MongoDB从不懂到装懂其四(数据备份、恢复、导入、导出)
- mongodb最大连接数、最大连接数修改