Mongodb Shell简单使用
MacOS安装MongoDB
brew install mongodb-community-shell
链接本地mongodb
$ mongo
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("1e6928ef-1ea2-4fe1-87d4-725290464e33") }
MongoDB server version: 6.0.6
WARNING: shell and server versions do not match
================
Warning: the "mongo" shell has been superseded by "mongosh",
which delivers improved usability and compatibility.The "mongo" shell has been deprecated and will be removed in
an upcoming release.
For installation instructions, see
https://docs.mongodb.com/mongodb-shell/install/
================
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
https://community.mongodb.com
---
The server generated these startup warnings when booting:
2023-06-12T21:18:15.436+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
---
>
显示所有数据库
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
yapi 0.000GB
切换数据库
> use yapi
switched to db yapi
查看所有文档集(表)
> show collections
adv_mock
adv_mock_case
avatar
follow
group
identitycounters
interface
interface_case
interface_cat
interface_col
log
project
statis_mock
token
user
wiki
查找记录
> db.user.find()
{ "_id" : 11, "study" : false, "type" : "site", "username" : "admin", "email" : "admin@admin.com", "password" : "289012770d85ffc3c1e32ec89e4a6420ef881429", "passsalt" : "4rxs6c6vc8d", "role" : "admin", "add_time" : 1688376343, "up_time" : 1688376343, "__v" : 0 }
更多操作参考菜鸟教程:https://www.runoob.com/mongodb/mongodb-create-database.html