{"id":800,"date":"2012-01-25T19:48:00","date_gmt":"2012-01-25T19:48:00","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/2012\/10\/mongodb-with-spring-data-project.html"},"modified":"2012-10-21T22:40:48","modified_gmt":"2012-10-21T22:40:48","slug":"mongodb-with-spring-data-project","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2012\/01\/mongodb-with-spring-data-project.html","title":{"rendered":"MongoDB with Spring Data project"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left\">All of us are observing the explosion of NoSql solutions these days. I get used to RDBMS but those are not a solution for all kind of challenges you might have. In my recent experience I got a chance to work with <a href=\"http:\/\/www.mongodb.org\/\">MongoDB<\/a> &#8211; document database. In this post I intent to cover some basics (and some advanced features in next post) of using <a href=\"http:\/\/www.mongodb.org\/\">MongoDB<\/a> together with <a href=\"http:\/\/www.springsource.org\/spring-data\">Spring Data<\/a> project. Before we start, small disclaimer: at the moment <a href=\"http:\/\/www.springsource.org\/spring-data\">Spring Data<\/a> is still in milestone phase so some classes \/ interfaces may change.<\/p>\n<p>Before we start, please download and run <a href=\"http:\/\/www.mongodb.org\/\">MongoDB<\/a> for your operating system. It&#8217;s very simple so I won&#8217;t spend time on this and let&#8217;s start with simple POM file for our project:<\/p>\n<pre class=\"brush: xml;\">\r\n    4.0.0\r\n\r\n    mongodb\r\n    com.example.spring\r\n    0.0.1-SNAPSHOT\r\n    jar\r\n\r\n    \r\n        UTF-8\r\n        3.0.5.RELEASE\r\n    \r\n\r\n    \r\n        \r\n            org.springframework.data\r\n            spring-data-mongodb\r\n            1.0.0.M3\r\n        \r\n\r\n        \r\n            log4j\r\n            log4j\r\n            1.2.16\r\n        \r\n\r\n        \r\n            org.mongodb\r\n            mongo-java-driver\r\n            2.5.3\r\n        \r\n\r\n        \r\n            org.springframework\r\n            spring-core\r\n            ${spring.version}\r\n        \r\n\r\n        \r\n            org.springframework\r\n            spring-context\r\n            ${spring.version}\r\n        \r\n    \r\n\r\n    \r\n        \r\n            springsource-milestone\r\n            Spring Framework Milestone Repository\r\n            http:\/\/maven.springframework.org\/milestone\r\n        \r\n    \r\n\r\n<\/pre>\n<p>There are two key dependencies here:<\/p>\n<p>&#8211; <a href=\"http:\/\/www.mongodb.org\/\">MongoDB<\/a> java driver<br \/>\n&#8211; <a href=\"http:\/\/www.springsource.org\/spring-data\">Spring Data<\/a> for <a href=\"http:\/\/www.mongodb.org\/\">MongoDB<\/a><\/p>\n<p>There are few ways to define <a href=\"http:\/\/www.mongodb.org\/\">MongoDB<\/a> inside your <a href=\"http:\/\/www.springsource.org\/\">Spring<\/a> application context. Let me show a bit verbose but more flexible one:<\/p>\n<pre class=\"brush: xml;\">&lt;beans xmlns:context=&quot;http:\/\/www.springframework.org\/schema\/context&quot; xmlns:mongo=&quot;http:\/\/www.springframework.org\/schema\/data\/mongo&quot; xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xmlns=&quot;http:\/\/www.springframework.org\/schema\/beans&quot; xsi:schemalocation=&quot;\r\n        http:\/\/www.springframework.org\/schema\/context \r\n        http:\/\/www.springframework.org\/schema\/context\/spring-context-3.0.xsd\r\n        http:\/\/www.springframework.org\/schema\/data\/mongo\r\n        http:\/\/www.springframework.org\/schema\/data\/mongo\/spring-mongo-1.0.xsd\r\n        http:\/\/www.springframework.org\/schema\/beans \r\n        http:\/\/www.springframework.org\/schema\/beans\/spring-beans-3.0.xsd\"&gt;\r\n\r\n    \r\n    \r\n  \r\n    \r\n \r\n    \r\n        &lt;constructor-arg index=\"0\" ref=\"mongo\" \/&gt;\r\n        &lt;constructor-arg index=\"1\" value=\"elements-db\"\/&gt;\r\n    \r\n\r\n        \r\n      \r\n\r\n    \r\n        &lt;constructor-arg name=\"mongoDbFactory\" ref=\"mongoDbFactory\" \/&gt;\r\n        &lt;constructor-arg name=\"mappingContext\" ref=\"mappingContext\" \/&gt;         \r\n     \r\n\r\n    \r\n        &lt;constructor-arg name=\"mongoDbFactory\" ref=\"mongoDbFactory\"\/&gt;\r\n        &lt;constructor-arg name=\"mongoConverter\" ref=\"converter\" \/&gt;        \r\n        &lt;property name=\"writeResultChecking\" value=\"EXCEPTION\" \/&gt;\r\n        &lt;property name=\"writeConcern\" value=\"NORMAL\"\/&gt;\r\n    \r\n \r\n    \r\n        \r\n    \r\n\r\n<\/pre>\n<p>The role of each bean here:<\/p>\n<ul>\n<li><strong>mongo<\/strong> defines connection to <a href=\"http:\/\/www.mongodb.org\/\">MongoDB<\/a> database (we rely on default settings, port 27027)<\/li>\n<li><strong>converter<\/strong> is used to convert Java classes to\/from <a href=\"http:\/\/www.mongodb.org\/\">MongoDB&#8217;s<\/a> DBObject (== JSON)<\/li>\n<li><strong>mongoTemplate<\/strong> exposes operations we can do over  <a href=\"http:\/\/www.mongodb.org\/\">MongoDB<\/a><\/li>\n<\/ul>\n<p>So, we are ready to go!<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>Here are few code snippets to start with:<\/p>\n<pre class=\"brush: java;\">package com.example.mongodb;\r\n\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.dao.DataAccessException;\r\nimport org.springframework.data.document.mongodb.CollectionCallback;\r\nimport org.springframework.data.document.mongodb.MongoOperations;\r\nimport org.springframework.data.document.mongodb.query.Index;\r\nimport org.springframework.data.document.mongodb.query.Index.Duplicates;\r\nimport org.springframework.data.document.mongodb.query.Order;\r\nimport org.springframework.stereotype.Service;\r\n\r\nimport com.mongodb.BasicDBObject;\r\nimport com.mongodb.DBCollection;\r\nimport com.mongodb.MongoException;\r\n\r\n@Service\r\npublic class MongoService  {\r\n    @Autowired private MongoOperations template;\r\n\r\n    public void createCollection( final String name ) {\r\n        template.createCollection( name  );\r\n    }\r\n\r\n    public void dropCollection( final String name ) {\r\n        template.dropCollection( name  );\r\n    }\r\n\r\n    public void insert( final Object object, final String collection ) {\r\n        template.insert( object, collection );\r\n    }\r\n   \r\n    public void createIndex( final String name, final String collection ) {\r\n        template.ensureIndex( \r\n            new Index()\r\n                .on( name, Order.DESCENDING )\r\n                .unique( Duplicates.DROP ), \r\n            collection  \r\n        );\r\n    }\r\n \r\n    \/\/ Remove \/ save \/ ... operations here\r\n}\r\n<\/pre>\n<p>That&#8217;s it with basics. Next post will cover advanced features: using bulk inserts, update or insert operation and executing <a href=\"http:\/\/www.mongodb.org\/\">MongoDB<\/a> commands. :)<\/p>\n<p>After the discussion about <a href=\"http:\/\/www.mongodb.org\/\">MongoDB<\/a> and <a href=\"http:\/\/www.springsource.org\/spring-data\">Spring Data<\/a> projects, i would like to show some advanced features (which could be available in next <a href=\"http:\/\/www.springsource.org\/spring-data\">Spring Data<\/a> milestone or release as part of core functionality). <\/p>\n<p>First of all, let us extend our <strong>MongoService<\/strong> with a method that counts documents in collection which match specific query.<\/p>\n<pre class=\"brush: java;\">package com.example.mongodb;\r\nimport java.util.Arrays;\r\nimport java.util.Collection;\r\n\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.dao.DataAccessException;\r\nimport org.springframework.data.document.mongodb.CollectionCallback;\r\nimport org.springframework.data.document.mongodb.MongoOperations;\r\nimport org.springframework.data.document.mongodb.convert.MongoConverter;\r\nimport org.springframework.data.document.mongodb.query.Criteria;\r\nimport org.springframework.data.document.mongodb.query.Index;\r\nimport org.springframework.data.document.mongodb.query.Index.Duplicates;\r\nimport org.springframework.data.document.mongodb.query.Order;\r\nimport org.springframework.data.document.mongodb.query.Query;\r\n\r\nimport org.springframework.stereotype.Service;\r\nimport org.springframework.util.Assert;\r\n\r\nimport com.mongodb.BasicDBObject;\r\nimport com.mongodb.DBCollection;\r\nimport com.mongodb.MongoException;\r\n\r\n@Service\r\npublic class MongoService {\r\n    public long countDocuments( final String collection, final Query query ) {  \r\n        return template.executeCommand( \r\n            \"{ \" +\r\n                \"\\\"count\\\" : \\\"\" + collection + \"\\\",\" +\r\n                \"\\\"query\\\" : \" + query.getQueryObject().toString() + \r\n            \" }\"  ).getLong( \"n\" );\r\n    }\r\n}\r\n<\/pre>\n<p>The approach for this particular functionality is to call native <a href=\"http:\/\/www.mongodb.org\/\">MongoDB<\/a> command <strong>count<\/strong> passing the query as a parameter. The returning structure contains number of documents in <strong>n<\/strong> property.<\/p>\n<p>Or, in more code-friendly way:<\/p>\n<pre class=\"brush: java;\">import org.springframework.dao.DataAccessException;\r\nimport org.springframework.data.document.mongodb.CollectionCallback;\r\n\r\nimport com.mongodb.DBCollection;\r\nimport com.mongodb.MongoException;\r\n\r\npublic long countDocuments( final String collection, final Query query ) {  \r\n    return template.execute( collection,\r\n        new CollectionCallback&lt; Long &gt;() {\r\n            @Override\r\n            public Long doInCollection( DBCollection collection ) \r\n                    throws MongoException, DataAccessException {\r\n                return collection.count( q.getQueryObject() ) );\r\n            }\r\n        }\r\n    );\r\n}\r\n<\/pre>\n<p>Next useful feature is bulk inserts. Please note, that in current version of <a href=\"http:\/\/www.mongodb.org\/\">MongoDB<\/a> 1.8.1, <strong>when there is a duplicate inside the collection of inserting documents, bulk insert stops on first duplicate and returns so all other documents won&#8217;t be inserted<\/strong>. Be aware of such behavior. Before moving to code snippet, let me introduce simple class <strong>SimpleDocument<\/strong> which we will be persisting to <a href=\"http:\/\/www.mongodb.org\/\">MongoDB<\/a>:<\/p>\n<pre class=\"brush: java;\">package com.example.mongodb;\r\n\r\nimport org.springframework.data.document.mongodb.mapping.Document;\r\n\r\n@Document( collection = \"documents\" )\r\npublic class SimpleDocument {\r\n    private String id;\r\n    private String name;\r\n    private String content;\r\n\r\n    public SimpleDocument() { \r\n    }\r\n\r\n    public SimpleDocument( final String id, final String name ) {\r\n        this.id = id;\r\n        this.name = name;\r\n    }\r\n\r\n    public String getName() {\r\n        return name;\r\n    }\r\n\r\n    public void setName(String name) {\r\n        this.name = name;\r\n    }\r\n\r\n    public String getId() {\r\n        return id;\r\n    }\r\n\r\n    public void setId(String id) {\r\n        this.id = id;\r\n    }\r\n\r\n    public String getContent() {\r\n        return content;\r\n    }\r\n\r\n    public void setContent(String content) {\r\n        this.content = content;\r\n    }\r\n}\r\n<\/pre>\n<p>Following method inserts all documents as single bulk update:<\/p>\n<pre class=\"brush: java;\">public void insert( final Collection&lt; SimpleDocument &gt; documents ) {  \r\n    template.insert( documents, SimpleDocument.class );     \r\n}\r\n<\/pre>\n<p>Another very cool and useful feature to explore is <a href=\"http:\/\/www.mongodb.org\/\">MongoDB&#8217;s<\/a> <strong>upserts<\/strong> (more about this here http:\/\/www.mongodb.org\/display\/DOCS\/Updating): if document matching specific criteria exists, it will be updated, otherwise &#8211; new document will be inserted into collection. Here is a code snipped with demonstrates it by following use case: if <strong>SimpleDocument<\/strong> with such <strong>name<\/strong> exists, it will be updated, otherwise new document will be added to collection:<\/p>\n<pre class=\"brush: java;\">@Autowired private MongoConverter converter;\r\n\r\npublic void insertOrUpdate( final SimpleDocument document ) {\r\n    final BasicDBObject dbDoc = new BasicDBObject();\r\n    converter.write( document, dbDoc );\r\n\r\n    template.execute( SimpleDocument.class, \r\n        new CollectionCallback&lt; Object &gt;() {\r\n            public Object doInCollection( DBCollection collection ) \r\n                    throws MongoException, DataAccessException {\r\n                collection.update( \r\n                    new Query()\r\n                        .addCriteria( new Criteria( \"name\" ).is( document.getName() ) )\r\n                        .getQueryObject(), \r\n                    dbDoc,  \r\n                    true, \r\n                    false \r\n                );\r\n\r\n                return null;\r\n            }\r\n        }\r\n    );\r\n}\r\n<\/pre>\n<p>Please notice usage of <strong>converter<\/strong> bean which helps to convert Java class to <a href=\"http:\/\/www.mongodb.org\/\">MongoDB&#8217;s<\/a> DBObject. <\/p>\n<p>The last one I would like to show is <strong>findAndModify<\/strong> operation which does several things as one atomic sequence:<\/p>\n<p>&#8211; find document matching criteria<br \/>\n&#8211; perform update<br \/>\n&#8211; return updated document (or old one, depending on what are your needs)<\/p>\n<pre class=\"brush: java;\">public void findAndModify( final Query query, final Update update ) {\r\n    return template.execute( SimpleDocument.class,\r\n        new CollectionCallback&lt; SimpleDocument &gt;() {\r\n            @Override\r\n            public SimpleDocument doInCollection( DBCollection collection ) \r\n                    throws MongoException, DataAccessException {\r\n                return converter.read( SimpleDocument.class,       \r\n                    collection.findAndModify( \r\n                        query.getQueryObject(), \r\n                        null,\r\n                        null,\r\n                        false,\r\n                        update.getUpdateObject(),\r\n                        true,\r\n                        false\r\n                    ) \r\n                );\r\n            }\r\n        }   \r\n    );\r\n}\r\n<\/pre>\n<p>For now, those are all interesting use cases I encountered. Honestly, I am very excited about <a href=\"http:\/\/www.mongodb.org\/\">MongoDB<\/a> and strongly recommend it if it fits your application.<\/p>\n<p><strong><i>Reference: <\/i><\/strong><a href=\"http:\/\/aredko.blogspot.com\/2011\/07\/mongodb-as-your-persistence-layer.html\">Exploiting MongoDB together with Spring Data project: basic concepts<\/a>&nbsp;&amp;&nbsp;<strong><i>&nbsp;<\/i><\/strong><a href=\"http:\/\/aredko.blogspot.com\/2011\/08\/exploiting-mongodb-together-with-spring.html\">Exploiting MongoDB together with Spring Data project: advanced concepts<\/a>&nbsp;from our <a href=\"http:\/\/www.javacodegeeks.com\/p\/jcg.html\">JCG partner<\/a>&nbsp;Andrey Redko at the&nbsp;<a href=\"http:\/\/aredko.blogspot.com\/\">Andriy Redko {devmind} <\/a>blog.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>All of us are observing the explosion of NoSql solutions these days. I get used to RDBMS but those are not a solution for all kind of challenges you might have. In my recent experience I got a chance to work with MongoDB &#8211; document database. In this post I intent to cover some basics &hellip;<\/p>\n","protected":false},"author":141,"featured_media":187,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[112,113,30,321],"class_list":["post-800","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-mongodb","tag-nosql","tag-spring","tag-spring-data"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>MongoDB with Spring Data project - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"All of us are observing the explosion of NoSql solutions these days. I get used to RDBMS but those are not a solution for all kind of challenges you might\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2012\/01\/mongodb-with-spring-data-project.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MongoDB with Spring Data project - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"All of us are observing the explosion of NoSql solutions these days. I get used to RDBMS but those are not a solution for all kind of challenges you might\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2012\/01\/mongodb-with-spring-data-project.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2012-01-25T19:48:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-10-21T22:40:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mongodb-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Andrey Redko\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Andrey Redko\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/01\\\/mongodb-with-spring-data-project.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/01\\\/mongodb-with-spring-data-project.html\"},\"author\":{\"name\":\"Andrey Redko\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/771a6504862edc45322776832cbce413\"},\"headline\":\"MongoDB with Spring Data project\",\"datePublished\":\"2012-01-25T19:48:00+00:00\",\"dateModified\":\"2012-10-21T22:40:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/01\\\/mongodb-with-spring-data-project.html\"},\"wordCount\":595,\"commentCount\":7,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/01\\\/mongodb-with-spring-data-project.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/mongodb-logo.jpg\",\"keywords\":[\"MongoDB\",\"NoSQL\",\"Spring\",\"Spring Data\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/01\\\/mongodb-with-spring-data-project.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/01\\\/mongodb-with-spring-data-project.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/01\\\/mongodb-with-spring-data-project.html\",\"name\":\"MongoDB with Spring Data project - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/01\\\/mongodb-with-spring-data-project.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/01\\\/mongodb-with-spring-data-project.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/mongodb-logo.jpg\",\"datePublished\":\"2012-01-25T19:48:00+00:00\",\"dateModified\":\"2012-10-21T22:40:48+00:00\",\"description\":\"All of us are observing the explosion of NoSql solutions these days. I get used to RDBMS but those are not a solution for all kind of challenges you might\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/01\\\/mongodb-with-spring-data-project.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/01\\\/mongodb-with-spring-data-project.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/01\\\/mongodb-with-spring-data-project.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/mongodb-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/mongodb-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/01\\\/mongodb-with-spring-data-project.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"MongoDB with Spring Data project\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/771a6504862edc45322776832cbce413\",\"name\":\"Andrey Redko\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/16419ce8394173028eddaeb992859862bab50cfcf74589fa9bb9a3dd8bb27518?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/16419ce8394173028eddaeb992859862bab50cfcf74589fa9bb9a3dd8bb27518?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/16419ce8394173028eddaeb992859862bab50cfcf74589fa9bb9a3dd8bb27518?s=96&d=mm&r=g\",\"caption\":\"Andrey Redko\"},\"description\":\"Andriy is a well-grounded software developer with more then 12 years of practical experience using Java\\\/EE, C#\\\/.NET, C++, Groovy, Ruby, functional programming (Scala), databases (MySQL, PostgreSQL, Oracle) and NoSQL solutions (MongoDB, Redis).\",\"sameAs\":[\"http:\\\/\\\/aredko.blogspot.com\\\/\",\"http:\\\/\\\/ca.linkedin.com\\\/in\\\/aredko\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/andrey-redko\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MongoDB with Spring Data project - Java Code Geeks","description":"All of us are observing the explosion of NoSql solutions these days. I get used to RDBMS but those are not a solution for all kind of challenges you might","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2012\/01\/mongodb-with-spring-data-project.html","og_locale":"en_US","og_type":"article","og_title":"MongoDB with Spring Data project - Java Code Geeks","og_description":"All of us are observing the explosion of NoSql solutions these days. I get used to RDBMS but those are not a solution for all kind of challenges you might","og_url":"https:\/\/www.javacodegeeks.com\/2012\/01\/mongodb-with-spring-data-project.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2012-01-25T19:48:00+00:00","article_modified_time":"2012-10-21T22:40:48+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mongodb-logo.jpg","type":"image\/jpeg"}],"author":"Andrey Redko","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Andrey Redko","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2012\/01\/mongodb-with-spring-data-project.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/01\/mongodb-with-spring-data-project.html"},"author":{"name":"Andrey Redko","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/771a6504862edc45322776832cbce413"},"headline":"MongoDB with Spring Data project","datePublished":"2012-01-25T19:48:00+00:00","dateModified":"2012-10-21T22:40:48+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/01\/mongodb-with-spring-data-project.html"},"wordCount":595,"commentCount":7,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/01\/mongodb-with-spring-data-project.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mongodb-logo.jpg","keywords":["MongoDB","NoSQL","Spring","Spring Data"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2012\/01\/mongodb-with-spring-data-project.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2012\/01\/mongodb-with-spring-data-project.html","url":"https:\/\/www.javacodegeeks.com\/2012\/01\/mongodb-with-spring-data-project.html","name":"MongoDB with Spring Data project - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/01\/mongodb-with-spring-data-project.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/01\/mongodb-with-spring-data-project.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mongodb-logo.jpg","datePublished":"2012-01-25T19:48:00+00:00","dateModified":"2012-10-21T22:40:48+00:00","description":"All of us are observing the explosion of NoSql solutions these days. I get used to RDBMS but those are not a solution for all kind of challenges you might","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/01\/mongodb-with-spring-data-project.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2012\/01\/mongodb-with-spring-data-project.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2012\/01\/mongodb-with-spring-data-project.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mongodb-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mongodb-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2012\/01\/mongodb-with-spring-data-project.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"MongoDB with Spring Data project"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/771a6504862edc45322776832cbce413","name":"Andrey Redko","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/16419ce8394173028eddaeb992859862bab50cfcf74589fa9bb9a3dd8bb27518?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/16419ce8394173028eddaeb992859862bab50cfcf74589fa9bb9a3dd8bb27518?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/16419ce8394173028eddaeb992859862bab50cfcf74589fa9bb9a3dd8bb27518?s=96&d=mm&r=g","caption":"Andrey Redko"},"description":"Andriy is a well-grounded software developer with more then 12 years of practical experience using Java\/EE, C#\/.NET, C++, Groovy, Ruby, functional programming (Scala), databases (MySQL, PostgreSQL, Oracle) and NoSQL solutions (MongoDB, Redis).","sameAs":["http:\/\/aredko.blogspot.com\/","http:\/\/ca.linkedin.com\/in\/aredko"],"url":"https:\/\/www.javacodegeeks.com\/author\/andrey-redko"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/800","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/141"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=800"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/800\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/187"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=800"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=800"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=800"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}