Windows installation of mongodb



Download address:

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:

    destination: file
    path: H:\mongodb\data\log\mongod.log
    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:


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:


Add, delete, modify and search:


Add a document to the user collection


Update document


To view the document:
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:


Delete document:
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 […]