Category Archives: Development Practice

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

Metaspace in Java8

Metaspace in Java8One of the new features that we will see in Java8 is the introduction of Metaspace. Metaspace is nothing but a replacement of our old friend PermGen (Permanent Generation) space.

What is PermGen?
The permanent Generation is part of your heap space that is actually used to store meta-data information for the classes created by users and prior to Java 7, it is also used to store interned Strings (interned strings – used to remove String duplicates by internalizing them to reduce memory consumption). As of Java 7, intern strings also moved as a part of heap space to make the more space available in Continue reading Metaspace in Java8

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

Default Methods in Java 8 Explained – Part 2 (A comic way)

If you have missed out the first part of this story i.e Default Methods in Java 8 ,you can read it here , else you can read the recap of first part here.

Recap : Interface IRoleService (i.e project manager) decided to assign extra duties to all (developer,tester ,ba etc) who are working on the project by introducing a new method extraDuties() in its interface. After this introduction of new extra duties  , TesterServiceImpl (i.e Tester of the application) rebelled and clear that he won’t perform any extra duties.When senior manager came to know about this situation , he advised interface IRoleService to introduce default methods so that no body will be forced to provide an implementation for extraDuties().

Now before going ahead let’s look at the code how default methods will be invoked and what Continue reading Default Methods in Java 8 Explained – Part 2 (A comic way)