MongoDB is an open-source, document-oriented NoSQL database that stores information as JSON-like documents organized into databases and collections. Documents in one collection may have different fields and value types, enabling dynamic schemas. section 17.1
MongoDB organizes persisted data through three core levels:
- A database contains collections. section 17.1
- A collection contains documents and roughly corresponds to a relational table. section 17.1
- A document contains key/value fields and roughly corresponds to a relational row; fields need not be uniform across documents. section 17.1
Java applications can access MongoDB through Spring Data MongoDB, which supplies repositories, object mapping, annotations, derived queries, Spring integration, and Spring Boot support. A domain class can use @Document, @Id, @Indexed, compound-index annotations, @Transient, and @PersistenceConstructor to control persistence. section 17.2
User document and query
A CaveatEmptor user document stores fields such as username, firstName, lastName, registrationDate, email, level, and active, together with MongoDB's generated _id. MongoDB Compass can filter the collection with {"username":"john"}. section 17.1
MongoDB can also sit behind Hibernate OGM, allowing entities mapped with JPA annotations to be persisted and queried through EntityManager and JPQL. Tests create collections and documents, use transaction boundaries even for reads, and clean persisted entities afterward. section 18.2.3 section 18.4






