Skip to content

Query examples based on a tweets collection by means of MongoDB Java Driver and Spring MongoDB Project

Notifications You must be signed in to change notification settings

ozlerhakan/mongodb-query-examples

Repository files navigation

Query Examples

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.

What’s included

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

How to run

  1. Suppose you have MongoDB installed on your machine, if not, just download and install it.

  2. 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.

  3. 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)
  4. 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.

Using Eclipse

To generate Eclipse metadata (.classpath and .project files), do the following:

./gradlew eclipse

Once complete, it is ready to be imported into Eclipse IDE

Using IntelliJ

To generate IDEA metadata (.iml and .ipr files), do the following action:

./gradlew idea

About

Query examples based on a tweets collection by means of MongoDB Java Driver and Spring MongoDB Project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages