Author: Hiral Patel

Backup and Restore MongoDB Database(s)

This post discusses how to backup and restore mongodb database(s) quickly using mongodump and mongorestore. Backup all Databases mongodump dump all database(s) from your mongodb. The default location is <presentWorkingDirectory>/dump. ~ hpatel$ mongodump Backup specific Databases to specific directory We can explicity specify database using -d option. Location can be specified explicity using -o option. ~ hpatel$ mongodump -d demo -o /Users/hpatel/dump Restore all Databases Go to the default location where dump directory is present. mongorestore will restore all database under dump directory. ~ hpatel$ mongorestore Restore specific Databases from directory Use -d to specify a database to restore....

Read More

MongoDB Most Frequent Queries

This post shows the syntax of most frequent Monogo DB queries for quick reference. Create Operations Create Database You need to create a collection or insert few records in a database in order to persist a database in mongodb. Step 1 : use demo will make demo as our current working database. Step 2 : show dbs will not list demo database, because demo database is not persisted yet. Step 3 : db.createCollection("person") will create person collection in demo database. Step 4 : show dbs will list demo database. > use demo switched to db demo > show dbs...

Read More

MongoDB Update with Demo

This post discusses common update syntax for mongodb with a Demo. Syntax db.collection.update( <query>, <update>, { upsert: <boolean>, multi: <boolean>, writeConcern: <document>, collation: <document> } ) Query : Query Selectors Update : Modifications to apply Upsert : true means insert if document does not match. False means do not insert if document does not match. Default value is false. Multi : true means update all matching document, false means update single document. Default value is false. writeConcern : Read Official Documentation. collation : Specify collation to use for the update operation. Initialize Person Collection Create person collection and insert...

Read More

Explanation of Shallow Copy vs Deep Copy in JS

This post explains the difference between shallow copy and deep copy in javascript. Shallow Copy Shallow copy means copy only the reference. var original = {"prop1" : "Prop1", "prop2" : "prop2"}; console.log(JSON.stringify(original)); // {"prop1" : "Prop1", "prop2" : "prop2"} var shallowCopy = original; console.log(JSON.stringify(shallowCopy)); // {"prop1" : "Prop1", "prop2" : "prop2"} shallowCopy.prop1 = "ChangedProp1"; console.log(JSON.stringify(original)); // {"prop1" : "ChangedProp1", "prop2" : "prop2"} console.log(JSON.stringify(shallowCopy)); // {"prop1" : "ChangedProp1", "prop2" : "prop2"} Notes: In shallow copy, original and copied object shares the same properties. Shallow copy only copies the object reference. In Shallow copy, Change in copied object reflects in original...

Read More

Demo for File Upload using Drag and Drop in HTML

HTML provides support for Drag and Drop events. This post discusses how to upload file using drag and drop in HTML ? The following 4 events are used to identify activity in drag and drop area. dragenter : Fires dragenter event when something enters into drag area dragleave : Fires dragleave event when something leaves from drag area drop : Fires drop event when something is dropped into drag area dragover : Fires dragover event when something moves into drag area Explanation Following is the code snippet used in the demo to identify drag and drop events in HTML5....

Read More