博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mongodb笔记 getting started
阅读量:6822 次
发布时间:2019-06-26

本文共 3018 字,大约阅读时间需要 10 分钟。

基本概念

数据库名全部小写

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

可视化管理工具

再linux上不要使用robomongo,数据量较大时没法完整读取
推荐使用mongochef:

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

一些限制

嵌入文档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

{  
:
,
: {
:
}, ...}

Update Specification Documents

{  
: {
:
, ... },
: {
:
, ... }, ...}

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, anda 3-byte counter, starting with a random value.

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

你可能感兴趣的文章
scala----函数和构造函数区别
查看>>
Linux平台的boost安装方法
查看>>
重温关于进程间通信的方式
查看>>
Spring
查看>>
HBase安装配置
查看>>
ssh 连接非22端口服务器的方法:
查看>>
Linux基础入门
查看>>
org.hibernate.hql.internal.ast.QuerySyntaxException: user is not mapped
查看>>
图解排序算法之快速排序-双端探测法
查看>>
mysql
查看>>
程序中的bug程度分析
查看>>
[算法][LeetCode] Dynamic Programming(DP)动态规划
查看>>
12.8 Nginx用户认证
查看>>
11月15日云栖精选夜读:分布式服务框架Dubbo疯狂更新!阿里开源要搞大事情?...
查看>>
跨链技术的分析和思考
查看>>
大数据(hadoop-HDFS原理分析)
查看>>
usermod命令 、用户密码管理、 mkpasswd命令
查看>>
一周第三次课
查看>>
日常运维(一)
查看>>
SAP数据中心概述
查看>>