MongoDB

General Commands

Find

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# 关键字 + 操作符 匹配
db.movies.find({"title": {"$in": ["a", "b"]}})

# 字段匹配
db.c.find({"y": null})

# 正则表达式
db.users.find({"name": {"$regex": /joe/i }})

# 多个元素匹配数组
db.food.find({"fruit": {"$all": ["apple", "banana"]}})

# 指定偏移量和返回元素数量 (startIndex, pageSize)
db.blog.posts.findOne(criteria, {"comments" : {"$slice" : [23, 10]}})

Scripts

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
version: "3.6"

services:
  mongodb:
    image: mongo:latest
    container_name: mongodb
    restart: always
    ports:
      - "27017:27017"
    volumes:
      - ./data:/data/db

References

Licensed under CC BY-NC-SA 4.0
Get Things Done
Built with Hugo
Theme Stack designed by Jimmy