MongoDB Guide PDF
MongoDB Guide PDF
Download the latest production release of MongoDB from the MongoDB Download Center:
https://www.mongodb.com/download-center#community
1
For the full reference, go to:
https://docs.mongodb.com/getting-started/shell/tutorial/install-mongodb-on-windows/
Database Systems 236363 Technion – Israel Institute of Technology Winter 2017-2018
During the installation process you will be given the option to install MongoDB Compass, the official GUI
for MongoDB, in addition to MongoDB Server. We advise you to install it.
MongoDB requires a data directory to store all data. MongoDB’s default data directory path is the
absolute path \data\db on the drive from which you start MongoDB. Create this folder by running the
following command in a Command Prompt:
> md \data\db
Alternatively, you can specify an alternate path for data files using the --dbpath option to mongod.exe,
for example:
3. Start MongoDB
To start MongoDB, run mongod.exe. For example, at the Command Prompt, type:
This starts the main MongoDB database process. The waiting for connections message in the console
output indicates that the mongod.exe process is running successfully. Note: if the data directory does
not exist, the program will exit with an error message.
Run Compass by double-clicking the Compass icon appearing in the Desktop. Once Compass is running,
an initial connection dialog appears:
2
For the full reference, go to: https://docs.mongodb.com/compass/current/connect/
Database Systems 236363 Technion – Israel Institute of Technology Winter 2017-2018
Mongo Shell4
The mongo shell is an interactive JavaScript interface to MongoDB. You can use the mongo shell to
query and update data as well as perform administrative operations.
To start the mongo shell and connect to your MongoDB instance running on localhost with default port,
In the command prompt go to C:\Program Files\MongoDB\Server\3.6\bin, and type:
> mongo
> db
To switch databases, issue the use <db> helper, as in the following example:
For example, assume you a database called “mydb”. Create a JavaScript file with the name “myscript.js”
that contains the following lines:
3
For the full reference, go to: https://docs.mongodb.com/manual/reference/program/mongoimport/
4
For the full reference, go to: https://docs.mongodb.com/manual/mongo/
5
For the full reference, go to: https://docs.mongodb.com/manual/tutorial/write-scripts-for-the-mongo-shell/
Database Systems 236363 Technion – Israel Institute of Technology Winter 2017-2018
var c = db.getCollectionNames();
printjson(c);