mirror of
https://github.com/Estom/notes.git
synced 2026-04-23 18:11:47 +08:00
JavaScript&nodejs
This commit is contained in:
55
Database/MongoDB/增删查改.md
Normal file
55
Database/MongoDB/增删查改.md
Normal file
@@ -0,0 +1,55 @@
|
||||
## 1 常用命令行
|
||||
|
||||
show dbs显示数据库列表
|
||||
|
||||
show collections
|
||||
|
||||
|
||||
use dbname创建并切换db
|
||||
|
||||
|
||||
db.user.insert({josnstr})向数据表中插入数据
|
||||
|
||||
db.user.find()搜索数据表
|
||||
|
||||
db.user.drop()删除数据表
|
||||
|
||||
db.dropDatabase()删除数据库
|
||||
|
||||
## 2 常用查找命令
|
||||
|
||||
### 非条件查找
|
||||
|
||||
### 单条件查找
|
||||
|
||||
### 多条件查找and
|
||||
|
||||
### 正则表达式查找
|
||||
|
||||
### 查找结果过滤
|
||||
|
||||
### 查找结果排序
|
||||
.sort()
|
||||
|
||||
### 查询前五条数据
|
||||
.limit(5)
|
||||
|
||||
### 查询10条以后的数据
|
||||
skip(10)
|
||||
|
||||
### 查询计数
|
||||
|
||||
.count()
|
||||
|
||||
### 或查询
|
||||
.find({$or:{"name":"zhangsan","age":34}})
|
||||
|
||||
|
||||
|
||||
## 3 修改数据
|
||||
|
||||
db.uer.update({{"age":34},{$set:{"age":50}},multr:true})
|
||||
|
||||
|
||||
## 4 remove
|
||||
db.user.remove({age:234})
|
||||
18
Database/MongoDB/聚合管道.md
Normal file
18
Database/MongoDB/聚合管道.md
Normal file
@@ -0,0 +1,18 @@
|
||||
表的关联查询和聚合统计
|
||||
|
||||
|
||||
## 常用操作符
|
||||
|
||||
$project 制定显示的列
|
||||
|
||||
$match 条件匹配
|
||||
|
||||
$limit 限制结果的数量
|
||||
|
||||
$skip 跳过文档的数量
|
||||
|
||||
$sort 条件排序
|
||||
|
||||
$group 条件组合结果
|
||||
|
||||
$lookup 引入其他集合的数据
|
||||
24
Database/MongoDB/设置索引.md
Normal file
24
Database/MongoDB/设置索引.md
Normal file
@@ -0,0 +1,24 @@
|
||||
## 创建索引的命名
|
||||
|
||||
|
||||
|
||||
db.user.ensureIndex({"tablenanme":1})
|
||||
### 获取索引
|
||||
db.user.getIndexes()
|
||||
|
||||
|
||||
### 删除索引
|
||||
db.user.dropIndex({})
|
||||
|
||||
### 复合索引
|
||||
多个条件组成层次索引
|
||||
|
||||
|
||||
### 唯一索引
|
||||
(字段不能重复)
|
||||
|
||||
## 获取执行时间
|
||||
|
||||
db.tablename.find().explain("executionStats")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user