17 Working with Spring Data MongoDB

This chapter covers

  • Introducing MongoDB
  • Examining Spring Data MongoDB
  • Accessing a database with MongoRepository
  • Accessing a database with MongoTemplate

Document-oriented databases are one type of NoSQL database, where the information is kept as a key/value store. MongoDB is such a database program. Spring Data MongoDB, as part of the larger Spring Data umbrella project, facilitates the interaction of Java programs with MongoDB document databases.

17.1 Introducing MongoDB

MongoDB is an open source, document-oriented NoSQL database. MongoDB uses JSON-like documents to store the information, and it uses the concepts of databases, collections, and documents.

  • Database—A database represents a container for collections. After installing MongoDB, you will generally get a set of databases.
  • Collection —A collection is similar to a table in the world of relational database management systems (RDBMSs). A collection may contain a set of documents.
  • Document—A document represents a set of key/value pairs, equivalent to rows in RDBMSs. Documents belonging to the same collection may have different sets of fields. Fields that are common to multiple documents in a collection may contain data of different types—such situations are known as dynamic schemas.

Table 17.1 summarizes the terminology equivalences between relational databases and the NoSQL database MongoDB.

17.2 Introducing Spring Data MongoDB

17.3 Using MongoRepository to access a database

17.3.1 Defining query methods with Spring Data MongoDB

17.3.2 Limiting query results, sorting, and paging

17.3.3 Streaming results

17.3.4 The @Query annotation

sitemap