[This post will discuss about different types of write concern in MongoDB – Performance Vs Persistence.]
Controlling the write operations 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
It is quite possible for the first time 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
This post will talk about Update Multiple Documents MongoDB Java Example.
In the last few examples we 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
Below is the sample collection that we are using in our all the examples.
Documents : Continue reading Sample Collection, Documents & MongoUtils.java
This post will talk about upsert mongodb java example.
Consider a scenario where we have to
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
While working on the array modifiers example
, 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
This post is in continuation of our Update MongoDB Java Example series.
In the previous post we have seen 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.
Continue reading Array Modifiers Update MongoDB Java Example
One 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
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.
- Fetching all the documents from a collection.
- Fetching a subset of documents from a collection.
- Fetching only selected keys of a document from a collection.
- Exclude some keys of a document from a collection.
For this example the document that we are using will have structure something like this , it has Continue reading Querying MongoDB Java Example
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)