Detailed MongoDB database configuration and common commands

MongoDB installation
  1. Download from official website: https://www.mongodb.com/download-center/community----Introductionhttps://www.cnblogs.com/dreamsqin/p/10885038.html
  2. Install to the MongoDB directory of Disk D, and configure D:\MongoDB\bin to the environment variable path
  3. Create data and log folders under MongoDB
  4. Test whether MongDB is installed successfully
    -Open the cmd command line
    -Enter the D:\MongoDB\bin directory
    -Enter the following command to start the mongodb service: mongod --dbpath D:\MongoDB\data
    -Enter http://localhost:27017 in the browser (27017 is the port number of mongodb) Check, if the display is as follows, it means the connection is successful. If unsuccessful, you can check whether the port is occupied
    Insert picture description here
    -Ctrl+C to exit the database
Configure the local windows MongoDB service (after configuration, it can be set to start automatically after booting, you can directly start and shut down manually, and you can start it through the command line net start MongoDB.)
  1. Create a configuration file mongo.config under the path D:\MongoDB

     # mongod.conf
      
     # for documentation of all options, see:
     #   http://docs.mongodb.org/manual/reference/configuration-options/
      
     # Where and how to store data.
     storage:
       dbPath: D:\MongoDB\data
       journal:
         enabled: true
     #  engine:
     #  mmapv1:
     #  wiredTiger:
      
     # where to write logging data.
     systemLog:
       destination: file
       logAppend: true
       path:  D:\MongoDB\log\mongo.log
      
     # network interfaces
     net:
       port: 27017
       bindIp: 127.0.0.1
      
      
     #processManagement:
      
     #security:
      
     #operationProfiling:
      
     #replication:
      
     #sharding:
      
     ## Enterprise-Only Options:
      
     #auditLog:
      
     #snmp:
     #mp:
    
  2. Open cmd as an administrator, and cd to the D:\MongoDB\bin directory

  3. Input: mongod --config "D:\MongoDB\mongo.config" --install --serviceName "MongoDB", that is, install the service according to the mongo.config configuration file just created, and the name is MongoDB.
    Insert picture description here

  4. net start MongoDBStart or net stop MongoDBshut down the MongoDB service through the command line .

MongoDB command statement (basic)
  1. If the service is configured according to the above, only need to start the servicenet start MongoDB
  2. mongo----Connect to mongo database
  3. show dbs----View the database
  4. use project, db.dropDatabase()----Delete the database named project
  5. use project, db.createCollection('users')----Create users
  6. show collections----View the users just created
  7. db.users.insert({name:'zhangsan'})----Insert data to users
  8. db.users.find()----View users data

Guess you like

Origin blog.csdn.net/weixin_43996999/article/details/103837902