MongoDB mongosh terminal 常用命令 Mac

2021-12-24 10:09:00 浏览数 (1)

use help to get access to the frequent commands

代码语言:javascript复制
help

show all databases

代码语言:javascript复制
show dbs

use a certain database, use "newdb"

代码语言:javascript复制
use newdb

Delete

Delete All Documents¶

To remove all documents from a collection, pass an empty filter document {} to either the db.collection.deleteMany() or the db.collection.remove() method.

https://docs.mongodb.com/v3.2/tutorial/remove-documents/#delete-all-documents

DeprecationWarning: Collection.remove() is deprecated. Use deleteOne, deleteMany, findOneAndDelete, or bulkWrite.

eg. Delete all documents in "newcollection"

代码语言:javascript复制
db.newcollection.deleteMany({})

用 Compass 导入 json 文件时,文件内容的最外层要有 []

0 人点赞