Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongodb dynamic schemas with spring data mongodb

I'm trying to store configuration in MongoDB. I want the document schema to be dynamic so as to store different type of configuration in the collection. The configuration may consist of more than just simple string key-value pairs. While using spring-data-mongodb, I see that I need to define a class which is usually mapped to a mongodb. So, when I need to add more configuration to the collection, I need to make changes to the class. I don't really want to do this as I want to be able to modify configuration without code changes (and ideally without restarting long-running applications). Also, what I'm eventually storing is configuration which should be consumed by different services, so I can't really have a well-defined schema. Instead, I would want the services to pull configuration from the store (i.e. provide key, get value). This makes me doubt where spring-data-mongodb is the right choice for such a use-case. Is there any obvious solution or alternative to my use-case?

Thanks in advance.

like image 540
Swapnil Avatar asked Dec 18 '12 13:12

Swapnil


1 Answers

The obvious solution is use just the Java driver for MongoDB. The Java driver has an implementation of BSON's spec and you can work with BSON/JSON objects instead classes.

like image 140
Miguel Cartagena Avatar answered Nov 15 '22 03:11

Miguel Cartagena