In the previous post i.e Document
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→
This post will focus on the logical
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→
In the previous post we have seen
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 :
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.
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 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.
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 IRoleServiceto introduce default methods so that no body will be forced to provide an implementation for extraDuties().
Default methods in Java 8 or we can also call them defender methods is one of the new feature that you will see in Java 8. I would rather say it is one of the most awaited feature should have been introduced in the earlier versions itself.Anyways its never been late so that it can’t be used , I think finally its a great introduction by Oracle Java Team.
Now as we know in Java (prior to 8) all the implementation classes (non abstract) of an interface have to agree the interface contract and under that contract they have to provide the concrete implementations of all the methods available in interface that they are implementing , if you missed in providing implementation for even a single method ,compiler will start complaining about it.