I would like to be able to save and retrieve, among other things, a map card in the MongoDB collection. I use Java to access MongoDB through Morphia.
The example I use below is a collection containing documents detailing the owners of various cars. In this example, the number of vehicles of a particular make and model is stored on a map card
Most properties work without any problems, but for the case when the property is a display mapping defined as follows:
@Property("vehicles")
private Map<String, Map<String, Integer> vehicles = new HashMap<String, HashMap<String, Integer>>();
The object is created (some values are inserted into the map) and stored in the Mongo database, as you would expect:
"vehicles" : {
"FORD" : {
"FIESTA" : 1
},
"TOYOTA" : {
"COROLLA" : 1,
"PRIUS": 1
},
"BMW" : {
"SLK" : 1
}
}
, java- ( MongoDB , )) ...
Query<Owner> q = ds.find(Owner.class);
System.out.println(q.countAll());
Iterable<Owner> i = q.fetch();
for (Owner o : i) {
System.out.println(o);
}
... q.fetch().
, :)