Skip to content

planetapex/mongo-db-cheatsheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Mongo DB Getting started in 3 easy Steps

Status GitHub Issues GitHub Pull Requests License


๐Ÿง About

This is quick start for developers who want to be up and running in no time.

The 3 steps:

  • Setting up the environment, MongoDB Server, installing locally[recommended]
  • Seeding Sample dataset using this repository[recommended]
  • MongoDB shell cheat sheet, to Start Practicing the commands.

๐Ÿ“ Table of Contents

๐Ÿ Getting Started

While following along the guide, I recommend to install MongoDB locally on the system and use this repository to seed data. So that the we can follow the examples using the cheat sheet provided.

1. ๐Ÿ”ง Setting up the environment

In order to work with mongo db we need to setup an environment.

We need access to a Mongo DB server.

  • Installing Mongo DB locally on the system [Recommended]
  • Using the on-line database-as-a-service(daas) Mongo DB
  • Other Hosting mongo DB instance on-line e.g. AWS etc.
  • MongoDB on-line REPL

Installing Mongo DB locally on the system [Recommended]

There is a community edition that we can install for free. The original documentation shows how to install on each system, macOS, Windows and Linux systems. MonoDB installation

Here are a few points worth mentioning:

  • In Windows we can install the MongoDB server as a service, so it can automatically run on Windows load.
  • In Windows, we can also use chocolatey or scoop to install it.

Windows, install using chocolatey

https://medium.com/@zibon/installing-mongodb-in-Windows-like-ubuntu-5d6d2285dac6

Windows, install using scoop

Here is the one for scoop:

https://gist.github.com/basir/a812d6870c12d8bd2d53981bbeeefa7c

Using the on-line database-as-a-service(daas) of Mongo DB

MongoDB provides on-line database service as Atlas. We can sign-up for free to get a dabatase instance.

MongoDB Atlas OR MongoDB Atlas from mlab, 512-Mb free space.

Other Hosting mongo DB instance on-line e.g. AWS etc.

We can refer to this article to see what options we got to host your own mongo DB server. cheap-free-mongodb-hosting

MongoDB on-line REPL

Here are a few worth mentioning:

https://www.jdoodle.com/online-mongodb-terminal/ https://www.mplay.run/mongodb-online-terminal https://mongoplayground.net/

2. ๐Ÿš€ Sample Seed Data-set

If we need some comprehensive, dynamic dataset we can use either of the following:

Using this repository to seed dynamic dataset [Recommended]

Here is a summary of all the commands, However, read all to complete the configuration before using these commands.

summary of all the commands

clone https://github.com/planetapex/mongo-db-cheat sheet.git
npm install
node seed1.js

We can create our own datasets in a matter of minutes, just read about faker.js and make changes in seed1.js.

However, to get along the examples set out, please use the dataset as it is:

Clone the repository using:

clone https://github.com/planetapex/mongo-db-cheat sheet.git

Goto the repository directory on your system and run the following command:

npm install

This will install all the necessary npm packages.

Now, we need to configure our db string in order to connect to the database and seed the data.

Edit the file in config.db.js and put the relevant configuration:

Lastly, there is a variable noOfRecords defined for the number of documents to generate. Initially its value is set to 10,000. You can change it to your liking. However, A very high number in the millions would take some time to process, so please be patient.

The repository contains 3 files for seeding the data. All the 3 files seed the same data. So, We can use any one of them. Run any one of the following commands to seed the data.

node seed1.js
node seed2.js
node seed3.js

Other datasets available to seed data

There are plenty of data available for use as a sample dataset:

checkout the following for an idea: Question for MongoDB datasets

Sample JSON files

Clone or Get the JSON file from the following repository, MongoDB sample JSON files and run the following command:

mongoimport --db test --collection zips --file d:\sample\zips.json

Sample Northwind Database

Clone this repository Northwind CSV db

In Windows Powershell, Go to the repository directory and run the following commands:

Get-ChildItem "E:\temp\nw" -Filter *.csv | `
Foreach-Object {
    C:\Program_Files\MongoDB\Server\4.2\bin\mongoimport.exe -h localhost:55000 -d northwind -c $_.BaseName --type csv --file $_.FullName --headerline 
}

NB: The options -h localhost:55000 -d northwind, is the db string pieces.

MongoDb Documentation datasets

Ususally, when you follow the examples on mongo DB documentation website, they provide you with some dataset to work with.

The original documentation even gives sample dataset to work with:

Bios collection

Find() using bios collection

dbkoda

https://medium.com/dbkoda/mongodb-sample-collections-52d6a7745908

3. ๐ŸŽˆMongoDB shell cheat sheet, to Start Practicing the commands.

Go to the mongo db bin folder and ,

Here is the cheat sheet to get started in no time.

MongoDB Shell cheat sheet

โ›๏ธ Built Using

  • NodeJs - Server Environment
  • MongoDB - Database
  • Moongoose
  • Faker.js
  • lodash
  • perfy

โœ๏ธ Authors

About

Mongo DB CheatSheet

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published