but wont the above expect a document like envinfo { appName: "name, attributes {} }. basically with the above, 'attributes' would need to be a subdocument of envinfo. also this doesnt take into account the fact that some keys might contain other sub documents.
–
pdevaJul 27 '13 at 17:07

1

it's mongodb, it doesn't expect anything other than id (unless you use spring annotation to make it a mandatory field). if there can be other subdocuments, then use "private Map<String, Object> attributes;", but then it becomes cumbersome and totally schema-less, which is not what mongo is made for. You should consider using a different persistence solution.
–
JayzJul 27 '13 at 21:10

This way, getInfos() returns a Map<String,Object> you can explore with String keys when needed, and that can have nested Map.

For your dependencies, it is better not to expose the BasicDBObject field directly, so this can be used via interface in a code not including any MongoDb library.

Note that if there is some frequent accessed fields in envinfo, then it would be better to declare them as fields in your class, to have a direct accessor, and so not to spend to much time in browsing the map again and again.