Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/oatpp/example-mongodb
Example project how to work with MongoDB
https://github.com/oatpp/example-mongodb
cpp example mongodb oatpp
Last synced: 5 days ago
JSON representation
Example project how to work with MongoDB
- Host: GitHub
- URL: https://github.com/oatpp/example-mongodb
- Owner: oatpp
- License: apache-2.0
- Created: 2020-05-29T23:00:22.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-04-22T21:29:24.000Z (7 months ago)
- Last Synced: 2024-10-29T22:51:19.017Z (17 days ago)
- Topics: cpp, example, mongodb, oatpp
- Language: C++
- Homepage: https://oatpp.io/
- Size: 27.3 KB
- Stars: 10
- Watchers: 3
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# example-mongodb [![Build Status](https://dev.azure.com/lganzzzo/lganzzzo/_apis/build/status/oatpp.example-mongodb?branchName=master)](https://dev.azure.com/lganzzzo/lganzzzo/_build/latest?definitionId=27&branchName=master)
Example project how to work with MongoDB using [oatpp-mongo](https://github.com/oatpp/oatpp-mongo) mondule.
Project is a web-service with basic CRUD and Swagger-UI.
*Dockerfile and docker-compose.yaml files included.*More About Oat++:
- [Oat++ Website](https://oatpp.io/)
- [Oat++ Github Repository](https://github.com/oatpp/oatpp)
- [Get Started](https://oatpp.io/docs/start)## Overview
### Dependencies
- [oatpp](https://github.com/oatpp/oatpp)
- [oatpp-swagger](https://github.com/oatpp/oatpp-swagger)
- [oatpp-mongo](https://github.com/oatpp/oatpp-mongo)
- [mongocxx](http://mongocxx.org/) - Temporary dependency. Until the oatpp-mongo driver will be ready-to-use*### Project layout
```
|- CMakeLists.txt // projects CMakeLists.txt
|- src/
| |
| |- controller/ // Folder containing Controller where all endpoints are declared
| |- db/ // Database class is here
| |- dto/ // DTOs are declared here
| |- App.cpp // main() is here
| |- AppComponent.hpp // Service configuration is loaded here
| |- SwaggerComponent.hpp // Configuration for swagger-ui
|
|- utility/install-oatpp-modules.sh // utility script to install required oatpp-modules.
|- Dockerfile // Dockerfile
|- docker-compose.yaml // Docker-compose with this service and postgresql
```## Build and Run
### Using CMake
**Requires**
- mongocxx installed. To install mongocxx:
- On Mac `$ brew install mongo-cxx-driver`
- On Linux - See Installing mongocxx on Linux section.
- `oatpp`, `oatpp-swagger`, `oatpp-mongo` modules installed. You may run `utility/install-oatpp-modules.sh`
script to install required oatpp modules.```
$ mkdir build && cd build
$ cmake ..
$ make
$ ./example-mongodb # - run application.
```### In Docker
#### Dockerfile
To run the web-service only:
```
$ docker build -t example-mongodb .
$ docker run -p 8000:8000 -e DEMO_MONGO_CONN_STR='mongodb://localhost/UserDB' -t example-mongodb
```#### docker-compose
To run both web-service and mongodb:
```
$ docker-compose up
```### After run
Go to [http://localhost:8000/swagger/ui](http://localhost:8000/swagger/ui) to try endpoints.
## Installing mongocxx on Linux
Installing mongocxx on Linux is an unclear and painful process.
See [ubuntu-cmake-mongocxx/Dockerfile](https://github.com/oatpp/dockerfiles/blob/master/ci/ubuntu-cmake-mongocxx/Dockerfile)
for instructions that worked for us.