Category Archives: NoSql

Compound Indexes MongoDB Java Example

Compound Indexes MongoDB Java Example

Having a requirement on searchingIndexing in MongoDB multiple keys in a query or need the result in the sorted order on the basis of multiple keys this is where Compound Indexes come into the picture. If we look at our previous post example – Simple Index MongoDB Java Example,where we have created index on key username such that whenever we performs a query on userName key it always gives us the record in the optimal time and in sorted order of username. Now if I want my result to be in ascending order of age and descending order of username then in that case it won’t be optimized as results are not stored in the ascending order of age because we don’t have any index on age key. Continue reading Compound Indexes MongoDB Java Example

Share and Enjoy

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

Single Field Indexes MongoDB Java Example

Indexing MongoDB Java Example

Indexing in MongoDB works in theIndexing in MongoDB same way as it is used to work in relational databases.It helps in the fast retrieval of documents available in MongDB . Having an index over a collection ensures that least numbers of documents are scanned to find the documents matching search criteria. Hence having an understanding of indexes is very important for the efficient performance of your application. In this post we will cover: Continue reading Single Field Indexes MongoDB Java Example

Share and Enjoy

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

Write Concern MongoDB Performance Comparison

In the last post we have MongoDB Official Logoseen the difference among all the available write concerns in MongoDB. We have also seen that which write concern to choose in which scenario that mostly depends on the type of data you are dealing with.

In this post we will see a performance comparison of all the write concerns , in this test i have inserted 100K records for each type of write concerns and captured the time taken for them.

Below are the stats that I got after executing my test case. Continue reading Write Concern MongoDB Performance Comparison

Share and Enjoy

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

Types of Write Concern in MongoDB – Performance Vs Persistence

[This post will discuss about different types of write concern in MongoDB – Performance Vs Persistence.]
Controlling the write MongoDB Official Logooperations in an application is always an important aspect. Today almost all the frameworks that interact with datastores provide mechanism to let you know whether your write operation is successful or not. Now when we talk about in the context of MongoDB , it also provides you an ability called as Continue reading Types of Write Concern in MongoDB – Performance Vs Persistence

Share and Enjoy

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

MongoException multi update only works with $ operators

It is quite possible for the first MongoDB Official Logotime when you are working with Multiple documents update in MongoDB you might see this exception.
Exception in thread “main” com.mongodb.MongoException: multi update only works with $ operators Continue reading MongoException multi update only works with $ operators

Share and Enjoy

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

Update Multiple Documents MongoDB Java Example

This post will talk about Update Multiple Documents MongoDB Java Example.
In the last few examples MongoDB Official Logowe have seen that, we are using the default version of update() method , where it takes 2 arguments i.e. search criteria object and modified object. Whenever this version of update() method is executed it updates only Continue reading Update Multiple Documents MongoDB Java Example

Share and Enjoy

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

Upsert MongoDB Java Example

This post will talk about upsert mongodb java example.
Consider a scenario where we have to MongoDB Official Logo
write the logic such that – we will
search for a record in the database
and if it is available in database we
will update it else we will insert a
new record with same information.
Conventional solution for this type of problem is first you will try to find the record in MongoDB either using findOne() or find() , and on Continue reading Upsert MongoDB Java Example

Share and Enjoy

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

Can’t serialize class – MongoDB Illegal Argument Exception

While working on the array modifiers example MongoDb
, I was trying to use the $sort
modifier with $each and $push modifier
.In that example I added
an array of books to my original
document and was trying to sort it on the basis of one of the fields.As soon as I executed that method,i got our infamous IllegalArgumentException : Exception in thread “main” java.lang.IllegalArgumentException: can’t serialize class com.lotusmedia.mongo.models.Book (Can’t serialize class – MongoDB). Continue reading Can’t serialize class – MongoDB Illegal Argument Exception

Array Modifiers Update MongoDB Java Example

This post is in continuation of our Update MongoDB Java Example series.

In the previous post we have Logical Querying MongoDB Java Exampleseen some of the Atomic update modifiers provided by MongoDB with the help of a Java example ,that can be used to
update and add new key to a
document. Now we will move one step ahead and will look into the Array modifiers available in MongoDB. Below are the following Array Modifiers that we are going to cover in this post.

  • $push
  • $each
  • $slice

Continue reading Array Modifiers Update MongoDB Java Example