This is a project showing a way you can use ODM, a lightweight and unintrusive Object-Document Mapper.
Note: in order to run this, you must change the classpath entry referencing the odm
You can clone odm, run mvn package
on it for a more up-to-date version.
- Have MongoDb installed and running
- Create or modify the dbConfig.cfg file in the root of the project to configure the connection to MongoDb. It must contain the following:
#dbConfig.cfg
MONGO_ADDRESS=localhost
MONGO_DEFAULT_DATABASE=DEFAULT_DB
MONGO_PORT=27017
Selector selector = ODM.selectorForClass(TestSimpleBean.class);
TestSimpleBean bean = (TestSimpleBean) selector.get(Filters.eq("id", "0"));
Fetches a TestSimpleBean from the db where the id field is equal to 0 Note: You can pass any filters from the MongoDb driver library see: documentation
ODM.insert(Object object);
Inserts an object in the database specified in configuration in a collection of the name of the class inserted
ODM.update(Object object);
Updates an object previously inserted or fetched
ODM.delete(Object object);
Deletes an object previously inserted or fetched
You can also extend your object from DbObject class. It will enable you to call:
object.insert();
object.update();
object.delete();
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
This project started as a school project.
Adam Jimenez