Author Archive

mongoDB – import a CSV file in a database collection

Suppose if you have a CSV file with large number of records and you want to import it into  database collection then need to use mongoimport mongoimport --db users --collection contacts --type csv --headerline --file contacts.csv --db will specify database, --collection will represent contacts collection --type is representing that  CSV file --headerline is representing the

mongoDB – remove a document

In mongoDB we can remove a document like in SQL. In mongoDb we use remove function to remove a document. In remove function we specify some criteria that is like where clause in SQL if we want to remove a document where name is mike the we will do it like this. > db.users.remove({"name":"mike"});  

mongoDB – Multi update of documents

In mongoDB an update operation can be used in 4 ways 1. wholesale replacement of a document. 2. update individual field using $set operator 3. upsert  – do update or insert 4. multiupdate of a document We have already read about first 3 let us look at multiupdate of a document. if we run following

mongoDB – Upserts – insert or update a document

If we use update command the document is updated only if that document record is present in collection. But if the requirement is that if document is present then we update it otherwise insert it as a new record. Then we can use upsert command. Suppose we run an update command as follows  > db.users.update({"name":"mike"},{$set:{$age:

mongoDB – Update a document in database

As in SQL We use update command for updating a record,  We do the same in No SQL databases. DB. We use update command. This approach is known as wholesale update of a document. Suppose we have a document in users collection. >  { _id :1, "name": "Mike"} Following is Syntax of update. > db.collection.update(query,

mongoDB – $all operator

The $all operator is used to selects the documents with the value of field is an array that contains all given elements. where the value of a field is an array that contains all the specified elements. This operator behaves like $and operator.  $all syntax is { <field>: { $all: [ <value1> , <value2> ...

mongoDB – $or operator

$or Operator in mongoDB or operator performs a logical or operation on an array of two or more  expressions and selects the documents that satisfy at least one of the expression. Syntax: { $or: [ { <expression1> }, { <expression2> }, ... , { <expressionN> } ] } Suppose we have an inventory collection. we

MongoDB – $exists and $regex operator

$exists As mongoDB is  schema less. In database some table can have different schema. for example if we have Persons database and in that database we have people collection.  If we need to know that whether a certain field exists in collection or not. Syntax: { field: { $exists: <boolean> } }   db.people.find( {

MongoDB – Drop a database

To drop a database in mongodb We can use “dropDatabase” command. First we need to use the database we want to drop. and then use that command like this. Suppose we have a database named students. >use students; db.dropDatabase();

Linux – Remove a directory with all files

In Linux if we need to remove a directory it can be done using command rmdir dirname But if directory is not empty then system will through an error. rmdir scripts This error comes up: rmdir: failed to remove `scripts’: Directory not empty To remove a directory that is full with other files or directories,