Windows installation of mongodb

Time:2021-4-20

download

Download address: https://www.mongodb.com/download-center/community/releases

The latest version I see now is 4 . four . 2, so download: HTTPS :// fastdl . mongodb . org / windows / mongodb – windows – x86_ sixty-four – four . four . two . zip

 

After downloading, I move and unzip it by myself, and I put it on disk h to H: mongodb

 

to configure

Create the data directory, and create dB and log under the data directory to store the database and log.

 

establish mongod.cfg The location of the file here is H: mongodb\ mongod.cfg

Write content in it:

systemLog:
    destination: file
    path: H:\mongodb\data\log\mongod.log
storage:
    dbPath:  H:\mongodb\data\db

 

Installation services

Run the command in the CMD window as an administrator:

H:\mongodb\bin\mongod.exe --config "H:\mongodb\mongod.cfg" --install

 

You can then use the following two commands:

Net start mongodb
Net stop mongodb

 

You can also find it in my computer management services and applications services.

 

Command line interaction

After the service is started, in the bin directory mongo.exe Double click directly to open the interactive environment.

 

 

To view the current database:
db

 

View all databases:

show dbs

If there is no data in the database, it will not be displayed.

 

View all collections:
show collections

 

Delete collection:
db.user.drop()

 

Add, delete, modify and search:

 

Add a document to the user collection
db.user.insert({username:’xiaoming’,age:2})

 

Update document
db.user.update({‘username’:’xiaoming’},{$set:{‘age’:111}})

 

To view the document:
db.user.find()
This one_ ID is the primary key, if not specified when inserting data_ ID, one will be created by default_ Add the ID to the document.

 

Number of documents to view:
db.user.count()

 

Delete document:
db.user.remove({age:111})
Delete all documents without conditions

 

Recommended Today

Deeply analyze the principle and practice of RSA key

1、 Preface After experiencing many dark moments in life, when you read this article, you will regret and even be angry: why didn’t you write this article earlier?! Your darkest moments include: 1. Your project needs to be connected with the bank, and the other party needs you to provide an encryption certificate. You have […]