13 April 2020

MongoDB

How to Install of MongoDB Community Edition:
To install MongoDB on Windows, first download the latest release of MongoDB from https://www.mongodb.org/downloads. Make sure you get correct version of MongoDB depending upon your Windows version. To get your Windows version, open command prompt and execute the following command.

C:\>wmic os get osarchitecture
OSArchitecture
64-bit

MongoDB requires a data folder to store its files. The default location for the MongoDB data directory is c:\data\db. So you need to create this folder using the Command Prompt. Execute the following command sequence.

C:\>md data
C:\md data\db

How to start mongo server
In the command prompt, navigate to the bin directory present in the MongoDB installation folder. Suppose my installation folder is D:\set up\mongodb

D:\set up\mongodb\bin>mongod.exe --dbpath "d:\set up\mongodb\data"
or
C:\Program Files\MongoDB\Server\3.6\bin>mongod.exe

This will show waiting for connections message on the console output, which indicates that the mongod.exe process is running successfully.

if you want to start mongo server with default data folder (c:\data\db) in listening mode then just run "mongod.exe" to run the server.

Now to run the server run below command from bin directory
mongo.exe

from db shell you can make a test like
db.test.save({a:1})
db.test.find()
create db with name dotDB
create collection/table with name project and template for DOT project.

Format below text in free time:
run mongo to connect to mongo instance
db.stats() to know db statistics
use dotDB
to switch to dotDB
show dbs
to list the databases in the system.

show collections

db.project.find({$and:[{"_id":"5ad07524acf885c26770e208"}]}).pretty()

db.project.find({$and:[{"projectName":"Demo Project"}]}).pretty()

db.project.find({$and:[{"_id":ObjectId(5ad07524acf885c26770e208)}]}).pretty()
db.project.find({$and:[{"_id":ObjectId(5ad07524acf885c26770e208)}]}).pretty()


db.project.update({"projectName":"Demo Project"},{$set:{'projectName':'237998'}})

db.project.update({"projectName":"237998"},{$set:{"platforms":[{"_id":null,"platformName":"FLEX","platformCode":"drive_flex","selected":true}]}})


No comments:

Post a Comment