Local setup¶
Last updated on: 13 January, 2020
Compiled by: Evan Tay
The purpose of this page is to quickly set up a local copy of MongoDB on Windows for local development purposes. Authentication will not be enabled or covered in this tutorial.
Installation and config¶
- Install MongoDB Community Edition, the standard configuration is fine.
- Take note of where your installation's
bin
folder is at, it should be atC:\Program Files\MongoDB\Server\4.2\bin
by default. - Add it to your environment variables. See guide here.
- Open your terminal - if you already have it opened, exit and re-open it to reload the enviroment variables.
- Enter
mongo
to access MongoDB.
Create a new collection¶
- Next, create a new collection, use the
use
command:
1 2 3 4 5 6 7 8 9 |
|
Info
Read https://docs.mongodb.com/manual/mongo/ for more information.
Create a new user¶
- Next, create a user with
readWrite
anddbAdmin
roles, using thedb.createUser()
command:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
Info
Read https://docs.mongodb.com/manual/reference/method/db.createUser/ for more information.
connection-string format¶
The connection-string is used to access the MongoDB instance from your applications (i.e. MongooseJS). The format of your connection-string is as follows:
1 2 3 4 5 6 7 8 9 |
|
Warning
If the username or password includes the at sign @, colon :, slash /, or the percent sign % character, use percent encoding. See https://docs.mongodb.com/manual/reference/connection-string/#examples for more information.
Authentication¶
Given that we are not enabling authentication, you can use either of the above connection-string URI formats.
Info
Read https://docs.mongodb.com/manual/tutorial/enable-authentication/ for more information.
Verify connection-string¶
To verify your connection-string, simply use mongo <mongoURI>
:
1 2 3 4 5 |
|
Resources¶
-
MongoDB's official guide to Install MongoDB Community Edition:
https://docs.mongodb.com/manual/administration/install-community/ -
Architect Ryan's guide to Add to the PATH on Windows 10:
https://www.architectryan.com/2018/03/17/add-to-the-path-on-windows-10/ -
MongoDB's official guide to The
mongo
Shell:
https://docs.mongodb.com/manual/mongo/ -
MongoDB's official guide to
db.createUser()
:
https://docs.mongodb.com/manual/reference/method/db.createUser/ -
MongoDB's official guide to Connection String URI Format:
https://docs.mongodb.com/manual/reference/connection-string/ -
MongoDB's official guide to Enable Access Control:
https://docs.mongodb.com/manual/tutorial/enable-authentication/