mangodb简单用法
2017-01-24 10:19
288 查看
一.什么是mongodb
基于分布式文件存储,介于关系型数据库和非关系型数据库
二.为什么用mongodb
1用json风格存储
2.文档数据库,数据字段可变
3.简单易用的查询方式,性能高,速度快
4.所有的数据类型都有索引
db.users.insertMany(
[
{
_id: 1,
name: "sue",
age: 19,
type: 1,
status: "P",
favorites: { artist: "Picasso", food: "pizza" },
finished: [ 17, 3 ],
badges: [ "blue", "black" ],
points: [
{ points: 85, bonus: 20 },
{ points: 85, bonus: 10 }
]
},
{
_id: 2,
name: "bob",
age: 42,
type: 1,
status: "A",
favorites: { artist: "Miro", food: "meringue" },
finished: [ 11, 25 ],
badges: [ "green" ],
points: [
{ points: 85, bonus: 20 },
{ points: 64, bonus: 12 }
]
},
{
_id: 3,
name: "ahn",
age: 22,
type: 2,
status: "A",
favorites: { artist: "Cassatt", food: "cake" },
finished: [ 6 ],
badges: [ "blue", "red" ],
points: [
{ points: 81, bonus: 8 },
{ points: 55, bonus: 20 }
]
}
]
)
语法
1.插入名字为 Alan的数据
db.users.insert({name:"Alan"})
2.查询年龄大于22
db.users.find({age:{$gt: 22}})
3.查询年龄大于22 和 state="A"
db.users.find({state:'A',age:{$gt: 22}})
4.查询年龄大于22 or state="A"
db.users.find({$or: [{state:'A',age:{$gt: 22}}]})
5.数组查询
db.users.find({favourites:{artist:"picasso",food:"pizza"}})
points数组 第一列数据 ponints小于等于85
db.users.find({'points.0.points':{$Ite: 85}})
基于分布式文件存储,介于关系型数据库和非关系型数据库
二.为什么用mongodb
1用json风格存储
2.文档数据库,数据字段可变
3.简单易用的查询方式,性能高,速度快
4.所有的数据类型都有索引
db.users.insertMany(
[
{
_id: 1,
name: "sue",
age: 19,
type: 1,
status: "P",
favorites: { artist: "Picasso", food: "pizza" },
finished: [ 17, 3 ],
badges: [ "blue", "black" ],
points: [
{ points: 85, bonus: 20 },
{ points: 85, bonus: 10 }
]
},
{
_id: 2,
name: "bob",
age: 42,
type: 1,
status: "A",
favorites: { artist: "Miro", food: "meringue" },
finished: [ 11, 25 ],
badges: [ "green" ],
points: [
{ points: 85, bonus: 20 },
{ points: 64, bonus: 12 }
]
},
{
_id: 3,
name: "ahn",
age: 22,
type: 2,
status: "A",
favorites: { artist: "Cassatt", food: "cake" },
finished: [ 6 ],
badges: [ "blue", "red" ],
points: [
{ points: 81, bonus: 8 },
{ points: 55, bonus: 20 }
]
}
]
)
语法
1.插入名字为 Alan的数据
db.users.insert({name:"Alan"})
2.查询年龄大于22
db.users.find({age:{$gt: 22}})
3.查询年龄大于22 和 state="A"
db.users.find({state:'A',age:{$gt: 22}})
4.查询年龄大于22 or state="A"
db.users.find({$or: [{state:'A',age:{$gt: 22}}]})
5.数组查询
db.users.find({favourites:{artist:"picasso",food:"pizza"}})
points数组 第一列数据 ponints小于等于85
db.users.find({'points.0.points':{$Ite: 85}})
相关文章推荐
- convert 3D matrix into diagonal block matrix
- CodeForces 304A Pythagorean Theorem II 【基础】【暴力】
- vs code golang插件记录
- Codeforces Yandex.Algorithm 2011 Round 2 D
- Ring3下无驱动移除winlogon.exe进程ctrl+alt+del,win+u,win+l三个系统热键,非屏蔽热键(子类化SAS 窗口)
- 掌握 Ajax,第 9 部分: 使用 Google Ajax Search API
- <svg/onload=prompt()>
- [golang]time.After 在select中使用的正确姿势(解决超时逻辑未生效bug)
- 倔强的驴小毛积累的go好文章
- 【通信框架】Google的开源通信框架protobuf概述
- oh my god
- brew install mongo
- go--互斥锁
- GOT表和PLT表知识详解
- django中的事务
- 采访:关于Go语言和《Go Web编程》
- go map深度拷贝
- 关于goneaway及499
- Google搜索被屏蔽的完美解决方法
- Go语言小爬虫--第一步