Monthly Archives: April 2016

PowerShell – SQL Databases Backup Status Report of Multiple Servers

  This post is a requirement from one of my blog reader. There are plenty of scripts available to get the backup status of the databases across multiple server. The  requirement is to read a server name and application names … Continue reading

Posted in Backup and Restore, PowerShell, SQL | Tagged , | 13 Comments

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

SQL DB Details Of Multiple Servers Using PowerShell

  One of my blog reader requested me to get the DB details(Server,DBName,Size,SpaceAvailable,LogSize,PercentUsed Log Space,compatiblilty mode, recovery model etc:-) using PowerShell hence this post is written. The power of PowerShell is to capture an output of DBCC commands and store … Continue reading

Posted in PowerShell, SQL | Tagged , | 4 Comments

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

MongoDB -Get Size, RowCount, CollectionSize

There are two different ways of getting the desired result The first method is iterating through each collection using for loop and displaying the result cols = db.getCollectionNames(); for (index = 0; index < cols.length; index++) { var coll = … Continue reading

Posted in MongoDB | Tagged , , | Leave a comment

MongoDB – Local and Remote Connections in Mongo Shell

To Install and Getting started with MongoDB refer the below links Getting Started with MongoDB Install MongoDB 3.2 on Windows Installation Guide How to access Mongo instance Open a terminal session or command window. For a local connection to mongod, … Continue reading

Posted in MongoDB | Tagged , , | Leave a comment