Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 

Basic MongoDB Queries

1) Create a "testDB" database. use testDB 2) Create a collection name "users" and adding the value together using single command.   db.logins.insert({username:"neetu"}) or  First create a collecti...

MongoDB Installation steps for Ubuntu

MongoDB is a free and open source document  based DBMS . Use the following command for MongoDB installation: 1) Execute the following command to import the public GPG Key.    sudo apt-key adv --keyserver hkp://keyserver...

MongoDB Connection With PHP

The MongoDB is built to work with your current web server, but not PHP. To communicate PHP with MongoDB server you need to install PHP-MongoDB driver. The PHP-MongoDB driver is a PHP extension library. The presently maintained driver for the Mong...

Data Modelling With MongoDB

Data in MongoDB contains a versatile schema. Documents that are in a same collection don't need to have an equivalent set of fields or structure, and common fields in an exceedingly collection's documents could hold differing kinds of dat...

MongoDB - Indexing

Indexes in MongoDB effective execution of query, Otherwise MongoDB must scan all documents inside of the collection to fetch document match the find statement. This scanning process is profoundly inefficient and require the MongoDB to handle a va...

MongoDB supported datatypes

Supported datatypes by MongoDB is given below: String: That is normally employed datatype for you to store the data. String inside mongodb have to be UTF-8 legitimate. Integer: This kind is utilized for you to store a new statistical worth....

Connecting to remote mongodb database via SSH

Hi friends, So many times developer face an issue of not able to connect to their mongo db using a GUI tool, If the mongo is installed on a remote server There is a solution of connecting to remotely installed mongodb via SSH First open your ...

How to update multiple array elements in mongodb

Hello Everyone, In this blog we will discuss about how to update multiple array elements in MongoDb using a single query. Let say we have a collection in MongoDb named "Form" which consists of the below available documents: > db.Form...

MongoDB Get names of all keys in collection

Hello All, In this blog we will discuss about how to get all keys in mongoDb collection. Sometimes we are in a situation in which we want only the keys not the data itself from the collection. So as a result you can try by following belo...

How to query mongodb with like?

Hello All, In this blog we will discuss about how to query mongodb with "like". In MySql you might have normally used below code to find by like select * from users where name like '%text%' But for using like in mongoDb you have t...

PHP Code to connect to MongoDB

To connect MongoDB with PHP you need to install MongoDB php driver. After you successful install MongoDB php driver, you need to create connection with MongoDB. MongoDB default port is 27017. To connect with localhost and default port $conn...

Retrieve only the queried element in an object array in MongoDB collection

Suppose we want retrieve only the queried element in an object array then we need to perform mongo query like below. Let me explain with this help of example. { _id: 4, zipcode: "63109", students: [ { name: "ankit", scho...

How do I perform the SQL Join equivalent in MongoDB

MongoDB does not have joins but sometimes we want references to documents in other collections. For this we have to use population. Population is the way of matching the specified paths in the document with document(s) from other collection(s)....

MongoDB Query Plan & Optimization

Indexes improve the efficiency of read operations by reducing the amount of data that query operations need to process. Create index for a collection : The index can be defined in schema of collection. Consider the following collection Accounts...

MongoDB Query Optimization using explain

The MongoDB query optimizer processes chooses the most efficient query plan form the available indexes. Then mongoDB query system use this index to execute and return the result. You can use the db.collection.explain() or the cursor.explain() ...

MongoDB Sharding explained

Sharding is a method for storing data into multiple distributed machines. Database systems with large data sets and high throughput applications can challenge the capacity of a single server. To prevent this MongoDB Sharding concept used. In S...

Two Phase commits in MongoDB

Hello All, In this we will discuss about how to perform two phase commit in MongoDB. Consider a example where funds will be transferred from one account to another. In a relation database approach we just subtract fund from account a and ad...

How to query mongodb with like

In MySql you have normally used below code to find by like select * from users where name like '%text%' But in order to use like in mongoDb you have write the below code:- You can use the actual regex object via MongoRegex db.collec...

Displaying Cursor Information in MongoDB

As we know cursor in mongoDB can be defined as return value of query run to mongoDB. The information of can be display using cursor.explain() function as show in below: db.collection.find().explain() The explain() method returns a documen...

Cursor In MongoDB

In mongo shell when find() query executed it return cursor with all document in the collection. However, if the returned cursor is not assigned to any variable then first 20 documents iterated automatically. In other word when a query run to m...

MongoDB : Javascript function

MongoDB - Javascript function $where operator : It uses to either a string containing a JavaScript expression. The full JavaScript function also used in the query system. This feature available after MongoDB version >= 2.4. List of prop...

MongoDB : $exist and $type operator

MongoDB - $exist and $type operator $type operator : It matches values based on their BSON type. e.g. We want to fetch documents from the collection which contains the value of "city" is only null. db.collection.find( { "city" : { $typ...

MongoDB : Regex

MongoDB - Regular Expression In MongoDB if we need to find record with certain pattern, then we can use regular expression. It is also "like" query in SQL. e.g. If we want to find user email matching with "findnerd.com" pattern. db.colle...

MongoDB : Sorting

MongoDB - Sorting In any application we need to show list in certain order. Generally we show's user feeds in descending order. This can be achieve in MongoDB through "sort" properties. e.g. We need to sort student name in ascending order....

MongoDB : Limit and Skip

MongoDB - Limit with Skip Often we need to implement pagination in any application. We can use "limit" with "skip". "skip" will select record from given index. e.g. We need to find 10 record started form 10th index. db.collection.find()....

MongoDB : Skip

MongoDB - Skip Query Sometime we need to find out certain number of record after a certain number of record. e.g. We need to find out 10 record start after 10th index db.collection.find().skip(10).pretty(); It is equivalent in SQl: ...

MongoDB : Limit

MongoDB - Limit Query Sometime we need to find out certain number of record. In MongoDB we can achieve this through "limit" option. e.g. We need to find 10 record from any collection. db.collection.find().limit(10).pretty(); It is e...

Download mongoDB data as csv file

Want to export MongoDB collection data to a csv file use mongoexport utility that produces data in JSON or CSV format. Use the following command to export data: mongoexport --host <hostName> --db <databaseName> --collection <...

Restore Directly from a Snapshot

As explained on post how to archive a snapshot, Now to restore a backup without writing to a compressed gz file from created archive, use the following sequence of commands: umount /dev/vg0/snap_db-01 lvcreate --size 1G --name mdb-new vg0 dd...

Restore a Snapshot

As explained on post how to archive a snapshot, Now to restore a snapshot from created archive, use the following sequence of commands: lvcreate --size 1G --name mdb-new vg0 gzip -d -c snap_db-01.gz | dd of=/dev/vg0/mdb-new mount /dev/vg0/md...

Creating a mongDB snapshot with LVM

Snapshot can be represented by creating pointers (equivalent to hard links ) between special snapshot volume and live data. The snapshot process uses a copy-on-write strategy. As a result the snapshot only stores modified data. The primary pu...

Mongodb Error Could not connect to a primary node for replica

Could not connect to a primary node for replica set <Moped::Cluster nodes=[<Moped::Node resolved_address="127.0.0.1:27017">] If you found above error then first check sudo service mongodb status If yes, then run following co...

How to solve [MongoError: connect ECONNREFUSED]

Hello Readers, I came across a solution while working on mongodb and would like to share with you all in case you face any such problem while working on mongodb. If you are coming across the error like the following: Connection error: {...

How to make group by query in MongoDb

Making a group by query in traditional database like MySQL,MySQL etc in quite easy but when its come to NoSQL like MongoDb we have to twist it a bit to get result we want : There are two ways in which you can do group by in MongoDb : a) Usi...

Solution for Invalid Object ID in MongoDb

We usually have this kind of error while making query with mongodb "Uncaught exception 'MongoException' with message 'Invalid object ID'" , the main reason behind this kind of error is that :-> a) Id string for mongodb must be 24 hexadecim...

How to make like query in MongoDb

Below is the way you can make like query in MongoDb : It can basically be achieved by using MongoRegex $where=array(); if($param['searchfor']!=""){ $regexObj = new MongoRegex("/".$param['searchfor']."/ig"); ...

Why use NoSQL over Relational Database - Chapter 1

What is NoSQL? NoSQL is not a relational database it has been developed keeping in mind few of the drawbacks of relational database. It was developed for the purpose of data stored about users, objects and the frequency in which the data is ac...
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: