O'Reilly logo

MongoDB Cookbook by Amol Nayak

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Developing using spring-data-mongodb

From the perspective of developers, when a program needs to interact with a MongoDB instance, they need to use the respective client APIs for their specific platforms. The trouble with doing this is that we need to write a lot of boilerplate code, and it is not necessarily object-oriented. For instance, we have a class called Person with various attributes such as name, age, and address. The corresponding JSON document too shares a similar structure to this Person class as follows:

{
  name:"…",
  age:..,
  address:{lineOne:"…", …}
}

However, to store this document, we need to convert the Person class to a DBObject, which is a map with key and value pairs. What is really desired is to let us persist this Person class ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required