MongoDB installs and configures on Windows 2003


This document applies to the installation, configuration, and use of MongoDB 2.0.1 on Windows 2003.

Or download the latest stable version as needed.

Installation: Extract the compressed package after downloading to any directory. This article assumes that it is extracted to the [D:\\mongodb] directory.

Configuration: Create a directory for data directories and log files:

Create a log file:

In the above editor interface, use [alt+f] to call up the [File] menu, select the [Save] item, and then select the [Exit] item to exit the editor. Check whether there is a log.txt file in the log directory. The following steps can be performed. If there is no existing, you can directly create an empty log.txt file on the windows interface.

Starting the mongodb service

Creating mongodb as a windows system service and starting the mongodb service.

Enter mongodb's bin directory, use mongod to create services, pay attention to the directory parameter values.

Create a service
:mongod --install --serviceName mongodb --logpath d:\\mongodb\\data\\log\\log.txt --logappend --dbpath d:\\mongodb\\data\\db --directoryperdb

Parameters: directoryperdb, optional parameters, each database is stored in a separate folder.

Starting Services
:net start mongodb

Use: Log in to native mongodb

After the Mongodb service starts, open the command line tool.

Login: mongo

27017 is the default port for mongodb.

Logging in to remote mongodb

Login: mongo

27017 is the default port for mongodb

Basic Commands

Display the current database: db

Show all databases: show dbs

Create database: no command to create a database, you can First use [use test1] to switch the database. At this time, the database has not been created. After creating a collection under the database or adding data to the collection, the data [test1] is automatically created.

Switch database: use test

Display database collection: show collections

Create collection: db.createCollection(“users”)

View db Help for the command:

View help for the collection command:

Insert data:{“name”:&rdquo ;shiwenbin”,”age”:100})

Retrieving data: db.users.find()

Pagination: db.users.find().skip(2).limit (3)

skip, skimming the specified number of bars.

limit, get the specified number of bars.

Command Help: See the help() of any command for the help of any command to see the parameters and usage of this command.


Chinese garbled: After inserting Chinese code, it is normal to use code to read it, but to view the inserted Chinese in the command line tool, Show garbled. This is mainly caused by the encoding of the cmd window, because the encoding of the mongodb background is utf-8, which can be solved by modifying the encoding of the cmd window.

1) Open a cmd window, type [chcp 65001]

2) Then open the properties window of the cmd window and select any font other than “ dot matrix font in the font. Font

Copyright © Windows knowledge All Rights Reserved