Category Archives: MongoDB

SQL vs NoSQL

Introduction Despite the traditional relational DB world, there’s also a trend for NoSQL. The NoSQL databases that enable storing unstructured and heterogeneous data. The scalability features have risen it’s popularity to a greater extent in the current market. Horizontal scaling … Continue reading

Posted in MongoDB, NoSQL | Tagged , , , | Leave a comment

Why MongoDB?

MongoDB is Object-Oriented, simple, dynamic and scalable NoSQL database. It is based on the NoSQL document store model, in which data objects are stored as separate documents inside a collection instead of storing the data into columns and rows of … Continue reading

Posted in MongoDB | Tagged , | Leave a comment

Securing MongoDB – User Administration

The db.createUser(user, writeConcern) method used to create users.We need to provide the username, password and roles The definition of createUser as follows { user: “<name>”, pwd: “password>”, customData: { <User Tag> }, roles: [ { role: “<role>”, db: “<database>” }, { … Continue reading

Posted in MongoDB | Tagged , , , , | Leave a comment

MongoDB : Point in Time Restore/Recovery of MongoDB

This post demonstrates the methods of PIT recovery of the database. The step by step details of the recovery process is explained below The requirement for PIT restore/recovery is to setup a single node replica so that the oplogs can … Continue reading

Posted in MongoDB | Tagged , , , , , , , | Leave a comment

MongoDB : How to get Top, Bottom,Middle and Range of records

In MongoDB,the limit() method is used to limit the result set to be returned. You can also use this with various methods such as sort() and skip() for various combination of requirement. The MS SQL equivalent is TOP function >SELECT TOP 10 * … Continue reading

Posted in MongoDB | Tagged , , | Leave a comment

MongoDB – Insert,Update,Upsert and Delete Examples – CRUD

In MongoDB we have to use either insert() or save() method to add the document to a collection Insert Single document > db.employee.insert(      {      “employee_id”:1101,      “name”:”Prashanth”,      “sal”:90000,      “dob”: new Date(1983,2,3,5,20),      “department”:          [              ‘DB Amdin’,’DB Developer’          ],      “Location”:”New York”      }); Insert Multiple document – We have to use … Continue reading

Posted in MongoDB, Uncategorized | Tagged , , , , , , | Leave a comment

MongoDB – How to Copy Database

Using copydb Run the copydb under admin database with from,to, host parameters >use admin switched to db admin > db.runCommand({ copydb: 1, fromdb: “test”, todb: “new_test”, fromhost: “localhost” }) Using copyDatabase method The db.copyDatabase() method is used to copy a … Continue reading

Posted in MongoDB | Tagged , , | Leave a comment

MongoDB – List All the databases

The function getDBs() function returns all the database list db.getMongo().getDBs() The runCommand is a special type of query called a database command and its is used database administration. The listDatabases parameter provides a list of all existing databases. You can see all commands … Continue reading

Posted in MongoDB | Tagged , , , | Leave a comment

MongoDB -Get Total datasize of all DB’s

var sum = 0; db.getMongo().getDBs()[“databases”].forEach(function(x) { sum += db.getMongo().getDB(x.name).stats().dataSize }); print(sum ); OR db = db.getSiblingDB(“admin”); dbs = db.runCommand({ “listDatabases”: 1 }).databases; var sum1=0;dbs.forEach(function(database) { sum1+=db.getMongo().getDB(database.name).stats().dataSize }); print(sum1);

Posted in MongoDB | Tagged , , | Leave a comment

MongoDB – Drop database

The dropDatabase command drops the current database, deleting the associated data files. Different methods to drop database Method 1: 1. select the database which you want to delete >use < database name > 2. Then issue the below command >db.dropDatabase() … Continue reading

Posted in MongoDB | Tagged , , | Leave a comment