MongoDB for Java Developers
Table of Contents
MongoDB for Java Developers
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Introduction to MongoDB
Getting into the NoSQL movement
Comparing RDBMS and NoSQL databases
Living without transactions
Managing read-write concurrency
MongoDB core elements
The heart of MongoDB – the document
Understanding how MongoDB stores data
Data types accepted in documents
Installing and starting MongoDB
Installing MongoDB on Windows
Installing MongoDB on Linux
MongoDB start up options
Troubleshooting MongoDB installation
Mongo tools
Introduction to the MongoDB shell
Inserting documents
Querying documents
Choosing the keys to return
Using ranges in your queries
Using logical operators to query data
Updating documents
Deleting data
Beyond basic data types
Arrays
Embedded documents
Some useful functions
Securing database access
Summary
2. Getting Started with Java Driver for MongoDB
Getting the Mongo JDBC driver
Creating your first project
Creating a new Java project
Handling authentication
Inserting a document
Creating embedded documents
Inserting an array of data
Using your own ID in documents
Querying data
Restricting the search to the first document
Querying the number of documents in a collection
Eager fetching of data using DBCursor
Filtering through the records
Building more complex searches
Updating documents
Deleting documents
Deleting a set of documents
Performing operations on collections
Listing collections
Dropping a collection
Using the MongoDB Java driver version 3
Running the HelloWorld class with driver v.3
Managing collections
Inserting data into the database
Inserting embedded documents
Inserting multiple documents
Querying documents
Filtering through documents
Updating documents
Deleting documents
Summary
3. MongoDB CRUD Beyond the Basics
Seeing MongoDB through the Java lens
Extending the MongoDB core classes
Using the Gson API with MongoDB
Downloading the Gson API
Using Gson to map a MongoDB document
Inserting Java objects as a document
Mapping embedded documents
Custom field names in your Java classes
Mapping complex BSON types
Using indexes in your applications
Defining an index in your Java classes
Using compound indexes
Using text indexes in your documents
Searching for text by language
Searching for text by score
Coding bulk operations
Comparing plain inserts with BulkWriteOperations
Summary
4. MongoDB in the Java EE 7 Enterprise Environment
Entering into the Java EE land
Getting a Java EE Container
Downloading WildFly
Starting WildFly and testing the installation
Designing our application
Designing the schema
Building up the Enterprise project with NetBeans
Configuring WildFly on NetBeans
Creating our project
Adding Java classes
Compiling and deploying the project
Compiling and deploying from the shell
Running the application
Exposing the application to external clients
Adding RESTful web services to our application
Compiling and deploying the application
Summary
5. Managing Data Persistence with MongoDB and JPA
An overview of the Java Persistence API
Entering Hibernate OGM
Building a JPA project that uses Hibernate OGM
Configuring the project dependencies
Mapping the database collections
Configuring persistence
Coding the controller and EJB classes
Hibernate OGM and JP-QL
Coding a controller bean
Coding the views
The main view
The newCustomer view
The newOrder view
Compiling and running the example
A look into MongoDB
Using native queries in your Hibernate OGM
Summary
6. Building Applications for MongoDB with Spring Data
Introducing Spring Boot
Getting started with Spring Boot
Getting started with Spring Data
Using the Spring repository to access MongoDB
Coding our Spring Boot application
Mapping Java classes with Spring Data
Running the example
Customizing the repository storage
Using JSON queries in your repository classes
Serving MongoDB using Spring REST
Using the Mongo template component to access MongoDB
Building up the data access layer
Adding the Application class
Creating fine grained queries using Criteria
Summary
Index
· · · · · · (
收起)