This project is composed of 3 sub modules. These sub projects namely "java-driver-examples", "spring-data-repo-examples" and "spring-data-examples" work as 3 different ways in order to obtain the results of the specific queries with regard to a collection stored in MongoDB (mongod). While the first one uses only MongoDB Java Driver to retrieve the data, others make use of the Spring MongoDB approach for the same purpose.
mongodb-query-examples
|--build.gradle
|--gradle
| `--wrapper
| |--gradle-wrapper.jar
| `--gradle-wrapper.properties
|--gradlew
|--gradlew.bat
|--java-driver-examples
| |--build.gradle
| `--src
| `--java
| `--com
| `--kodcu
| `--mongodb
| `--driver
| |--MongoApp.java
| |--TweetDAO.java
| `--TweetDAOImp.java
|--settings.gradle
|--spring-data-examples
| |--build.gradle
| `--src
| `--java
| `--com
| `--kodcu
| `--mongodb
| `--spring
| |--MongoApp.java
| |--MongoConfiguration.java
| |--MongoConfigurationBeans.java
| |--TweetDAO.java
| |--TweetDAOImp.java
| `--twitter
| `--db
| |--Media.java
| |--MediaProperty.java
| |--Tweet.java
| |--TweetEntity.java
| |--URLEntity.java
| |--User.java
| `--UserEntity.java
`--spring-data-repo-examples
|--build.gradle
`--src
`--java
`--com
`--kodcu
`--mongodb
`--spring
|--MongoApp.java
|--MongoConfiguration.java
`--twitter
|--db
| |--Media.java
| |--MediaProperty.java
| |--Tweet.java
| |--TweetEntity.java
| |--URLEntity.java
| |--User.java
| `--UserEntity.java
`--repo
|--TweetDAO.java
|--TweetRepository.java
`--TweetRepositoryDAO.java
-
Suppose you have MongoDB installed on your machine, if not, just download and install it.
-
Download the tweets collection that are used in each sub project. Use the following command line to restore it on your running server:
$ mongorestore dump
If your mongod server runs on a different port, use
--port
command before dump. See the other details of mongorestore. This command should restore to a collection called "tweets" in a database called "twitter". Here is a gist that shows an example tweet document. -
To check out the projects and build from sources, do the following:
git clone https://github.com/ozlerhakan/mongodb-query-examples cd mongodb-query-examples ./gradlew build (--debug : to see comprehensive details)
-
Run the following command:
./gradlew run
This command runs "java-driver-examples", "spring-data-examples" and "spring-data-repo-examples" respectively. Note that, the database (
twitter
) is running on the local interface on port 27017.
To generate Eclipse metadata (.classpath and .project files), do the following:
./gradlew eclipse
Once complete, it is ready to be imported into Eclipse IDE