Mongodb Shell common operation commands

Table of contents

1. Start and stop mongodb service

Two, enter the shell operation

3. Commonly used shell commands


1. Start and stop mongodb service

Start: Command:  ./mongod -config ../data/mongodb.conf

 Shutdown command:  ./mongod -config ../data/mongodb.conf -shutdown

Two, enter the shell operation

Command: ./mongo

3. Commonly used shell commands

  • show dbs: Displays a list of databases.
  • db: display the current database, the default is test
  • show collections: Displays the collection of tables in the current database.
  • show users: show all users
  • use dbName: switch the current database
  • db.help(): Display database operation commands
  • db.collectionName.help(): Display collection operation commands

1. Create a database

mongodb does not have a command to create a database, if you want to create a database named admin, you need to run use admin first

2. Create a table (collection)

 

3. Insert data

 

4. Find all data

5. Query specified data

Find records with gender male

Find records in the specified column

6. Modify data

7. Delete data

8. Delete table (collection)

9. Delete the database

10. Exit the shell

Guess you like

Origin blog.csdn.net/weixin_64443786/article/details/130770722