Category Archives: NoSql

Atomic Update MongoDB Java Example

In the previous post i.e Document Logical Querying MongoDB Java Example
Replacement in MongoDB
we have
seen how we were updating the
document – first by getting the
document using findOne() , then
updating its values and finally
putting it back in the collection.
We can also achieve the same task
in a single step i.e skipping findOne() invocation and by using atomic update modifiers provided by mongodb. This post will focus on update mongodb java example. Continue reading Atomic Update MongoDB Java Example

Document Replacement using update MongoDB Java

In the previous posts we have seen examples Logical Querying MongoDB Java Example
on how we can query a MongoDB using Java. We have seen different ways in which we can invoke find() method and how to do comparison querying and logical querying. This post will focus
on updating of our existing documents present in our mongo database using Java.

Update MongoDB Java Example :

Here also, we will continue with the same example that we have used in our previous posts. Continue reading Document Replacement using update MongoDB Java

Logical Querying MongoDB Java Example

This post will focus on the logical Logical Querying MongoDB Java Example
operators that are available in
momgodb.I will use Java for the
illustration purpose of these
operators. You can use any of
the language for which mongo
driver is available. For the comparison operators you can refer the previous post here.
There are 4 logical operators that have been documented in mongodb specs.
We will continue with the same example that we have seen in the previous post. Continue reading Logical Querying MongoDB Java Example

Conditional Querying MongoDB Java Example

In the previous post we have seen  Conditional Querying MongoDB Java Example
different variations of find() method ,
but in real life we need much more than the exact matching  e.g we want to query  in ranges (using in ) , combine multiple conditions together (using OR , AND)  , using negation etc. In this post we will cover the comparison query operators that comes under the conditional querying in MongoDB :

Here, we will continue with the same example that we have used in the previous post , in Continue reading Conditional Querying MongoDB Java Example

Querying MongoDB Java Example

In the earlier post Mongodb java Hello World Example we have seen some basic operations on the MongoDB and searching the document was one of them there we had used find().In this post we will more focus on querying mongdb with java using find() method that is basically used for querying documents in mongodb collections. We will see that how we can use find() in different ways to meet our query needs.Below are the 4 basic scenarios that we are going to cover under querying mongodb java example.

  1. Fetching all the documents from a collection.
  2. Fetching a subset of documents from a collection.
  3. Fetching only selected keys of a document from a collection.
  4. Exclude some keys of a document from a collection.

Querying MongoDB with Java

For this example the document that we are using will have structure something like this , it has Continue reading Querying MongoDB Java Example

Remove() Vs Drop() in MongoDB

Once we have documents stored in our collection , we can remove all of the documents from it in two ways. Now choosing one over other is totally depends on your requirement.

  • Using remove()
  • Using drop()

This post will show a comparison on Remove() Vs Drop() in MongoDB.

remove() vs drop() in mongodb

Before using one of them lets try to look into the pros and cons of each other.

  1. Using Remove():  remove has two overloaded versions ,one in which we will pass the Continue reading Remove() Vs Drop() in MongoDB

MongoDB Java Hello World Example

In the previous post  we have seen some of the basics on the primary keys and ObjectId in MongoDB.Now its time to get our hands dirty with some code , here I am using Java to interact with our mongo database. In this MongoDB Java Hello World example we will cover the following points : –

MongoDB Java Hello World Example
MongoDB Java Hello World Example
  1. Connect to mongodb server
  2. Connect to a database / Create a new Database
  3. Create a new collection
  4. Insert a new Document
  5. Search a Document
  6. Update a Document
  7. Delete a Document Continue reading MongoDB Java Hello World Example

_id and ObjectId in MongoDB

MongoDB has its own style of storing the  documents in the collection and providing the uniqueness to these documents is an important aspect of MongoDB.
So , it is very important that before we go into the higher end of Mongo we should understand what are _id and ObjectId in MongoDB.

_id and ObjectIds in MongoDB-1
MongoDB Official Logo

In relational databases like Oracle , DB2,MySQL etc whenever we insert any row into the database of our application we never care about providing the Continue reading _id and ObjectId in MongoDB

Binary JSON (BSON)

To understand BSON we have to go back to JSON to understand why it was designed and that is to provide a light weight medium for transferring the data over the wire that can be serialized and deserialized very fast. BSON took this thing one step ahead.

Binary JSON or BSON is the binary version of JSON i.e javascript object notation.In simple terms we can also say that it is an extension over the conventional JSON.It supports all the features that are available in JSON that means anything that can be represented or processed in JSON can be done in BSON also,in addition to that BSON also provides some extra advantage over JSON.
BSON Specs can be seen here. Continue reading Binary JSON (BSON)

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

Install MongoDB as a Windows Service

In the previous post we have seen that how to install and configure mongo database server and how to connect to it using interactive javascript client.If you have read my previous post you will notice that while starting the mongo database server using mongod we are passing the location of where our data is going to reside using the –dbpath argument like this.

mongod --dbpath C:sauravmongodatadb

Actually this is not the ideal way of doing this and moreover not an recommended way because every time passing the dbpath location is an extra overhead.So, here comes the config file as a resuce, we are going to define this dbpath property and some other property in the config file such that mongod will read this config file while starting mongo database server. Continue reading Install MongoDB as a Windows Service

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS