How to Setup MongoDB and Use It...!!
MongoDB is a free and open source, cross platform, document oriented database program. Classified as a NoSQL database program. MongoDB uses JSON-like document with schemas. MongoDB is developed by MongoDB Inc.
MongoDB supports field, range queries and regular expression searches. Queries can return specific fields of document and also include user defined JavaScript functions. Queries can also be configured to returns a random sample of result of a given size.
These are the Key Featrures of Mongodb
- General purpose database, almost as fast as the key:value NoSQL type.
- High availability.
- Scalability (from a standalone server to distributed architectures of huge clusters). This allows us to shard our database transparently across all our shards. This increases the performance of our data processing.
- Aggregation: batch data processing and aggregate calculations using native MongoDB operations.
- Load Balancing: automatic data movement across different shards for load balancing. The balancer decides when to migrate the data and the destination Shard, so they are evenly distributed among all servers in the cluster. Each shard stores the data for a selected range of our collection according to a partition key.
- Native Replication: syncing data across all the servers at the replica set.
- Security: authentication, authorization, etc.
Now will see how to download and install MongoDB...
1) first you have do download and install the MongoDB to your computer.
Go to this link (Download mongodb) and download the software according to your windows type.
2) Open the exe file and install it.
3) Create a folder in C drive called "data" and then create a folder called "db" inside the data folder which you created first. (C:\data\db) Because data directory is used by MongoDB to save all the files related to databases.
4) Then run the command prompt and type this commands to check weather MongoDB is working.
- Go to the path where you installed the MongoDB
cd C:\Program Files\MongoDB\Server\3.4\bin
mongod
- Then type and run this comnnand
mongod
5) If you getting an error like this,
you have to update your windows using this file which is given in the link. select the correct uptede file according to your operating system.
Now will see basic Commands and Queries in MongoDB...
1) View available DBsshow dbs
2) View current DB
db
3) Create new DB or Switch to existing DB
use <database name>
4) Insert a Record
db.<collection name>.insert({ });
Example :- db.student.insert{
"name":"Damith Perera",
"age":"23",
"subjects":["SE","AF","SA"]
}
5) Find a Record
db.<collection name>find({ <propertes>})
Example :- db.students.find({"name":"Damith Perera"})
6) Add a new value to existing Record
db.<collection name>.update({<properties>},{$push:{<properties>}})
Example :- db.students.update({"name":"Damith Perera"}, {$push: {"subjects":"DS"}})
7) Update a new value with existing value
db.<collection name>.update({<properties>},{$set:{"properties"}})
Example :- db.students.update({"name":"Damith Perera"}, {$set: {"age":"24"}})
8) Remove a Record
db.<collection name>.remove({<properties>})
Examples :- db.students.remove({"name":"Damith Perera"})
Comments
Post a Comment