MongoDB Installation, Queries Practice Set | Hire MongoDB Expert

Requirement

Create a collection names "Contrib_data" using Contrib_data.csv file in canvas under a MongoDB database named assign.


1. What is the count of records where the transaction_amt is less than $10?


2. Add a new field named "donar_cat" to the collection "Contrib_data".

donar_cat field should have a value of "big_fish" if the transaction_amt is greater than or equal to $500 and "small fish" if transaction_amt is less than $500. Print out total amount for each donar_cat as final output.


3. Give the top 5 cmte_received by transaction amount.


4. Give the top 5 cmte_received by transaction amount that candidate 'BACHMANN, MICHELE' gave money to.


Installation

First go to the MongoDB official website:

www.mongodb.com


















Click Try free at right corner.



















And after this choose server button. Choose OS, and package MIS and start down load.



















Click on downloaded file and then Click next button


















Accept term and condition, and then click on next button.


Select Choose type: complete




































Click on next


















Again Click next


And then after installation is started


















After MongoDB installation successfully finish you click Finish button on next window.


Go to the Program files ->MongoDB->bin


Copy the path and goto the command prompt and paste the path as like and press enter














After this type mongod command and press Enter

Server installation started:

Some exception raise regarding path to create data->db inside C directory.


And after run mongod command to run server.

Open Another command promt.


And run again:

cd C:\Program Files\MongoDB\Server\4.0\bin 

press enter

run mongo command.

After this to show all database inside use :

>Show dbs 

command


Output: it exist default database inside

Admin 0.000GB
Config  0.000GB
Local 0.000GB

Create our database use command as:

>use naveen 

press enter

Switched to db Naveen

>Show dbs

Output

Admin 0.000GB
Config  0.000GB
Local 0.000GB

Not show naveen database because not inserted data so insert data use this command.


Syntax:

(db.name of collection.insert({“keyname”:”value”}))


Example:

>db.books.insert({“name”:”mongo book”})           

Press enter and create this collection:

Result:

WriteResult({“nInserted” : 1})

To show database use

>show dbs

Result:

Admin 0.000GB
Config 0.000GB
Local 0.000GB
Naveen 0.000GB


To list out all the collection use this command

>show collections;

Result: inside the naveen database

Books


Show element inside books collection:

>db.books.find()

Output:

{“_id” : ObjectId(5cd….c1), “name” : “mongo book”}

Close command promt

Again open

Run mongod from anywhere show error internal and external command so need to set environment variable:


C:\users\naveen kumar\mongod 

press enter


Error External and Internal command

Set Environment Variable:

Choose path where django installed (C:\Program Files\MongoDB\Server\4.0\bin) and go to system start window choose system and click Advanced system setting. And then click on Environment Variable.


In system variable box find path double click on it.


Click on new and add the path

C:\Program Files\MongoDB\Server\4.0\bin


Now you can run anywhere by cmd like:

C:\users\naveen kumar\mongodb 

press enter



Import csv file into MangoDB


Step 1