Mongo_如果快速学习Mongo
MongoDB与RDMS(关系型数据库)比较,如下图所示
RDMS | MongoDB |
---|---|
database(数据库) | database(数据库) |
table (表) | collection( 集合) |
row( 行) | document( BSON 文档) |
column (列) | field (字段) |
index(唯一索引、主键索引) | index (支持地理位置索引、全文索引 、哈希索引) |
join (主外键关联) | embedded Document (嵌套文档) |
primary key(指定1至N个列做主键) | primary key (指定_id field做为主键) |
什么是BSON
BSON是一种类似于JSON的二进制形式的存储格式,简称Binary JSON,它和JSON一样,支持内嵌的文档对象和数组对象,但是BSON有JSON没有的一些数据类型,如Date和BinData类型。BSON有三个特点:轻量性、可遍历性、高效性。
下表列出了MongoDB中Document可以出现的数据类型:
数据类型 | 说明 | document举例 |
String | 字符串 | {key:“cba”} |
Integer | 整型数值 | {key:2} |
Boolean | 布尔型 | {key:true} |
Double | 双精度浮点数 | {key:0.23} |
ObjectId | 对象id,用于创建文档的id | {_id:new ObjectId()} |
Array | 数组 | {arr:[“jack”,“tom”]} |
Timestamp | 时间戳 | { createTime: new Timestamp() } |
object | 内嵌文档 | {student:{name:“zhangsan”,age:18}} |
null | 空值 | {key:null} |
Date或者ISODate | 日期时间 | {birthday:new Date()} |
Code | 代码 | {setPersonInfo:function(){}} |