0
votes

I have persistent class similar to the following:

public class Invoice {

    private Map<String, PurchasedItem> itemMap;

}

The PurchasedItem class looks like:

public class PurchasedItem {

    private String name;

    private int quantity;

}

Let's just say, I have good reasons not to store PurchasedItem objects into their own collection, and I want to store each of them under their respective parent Invoice objects. How do I annotate my classes so that Spring Data MongoDB automatically maps the itemMap correctly to something like:

"itemMap": {
    "tomato": {
        "name": "tomato",
        "quantity": 5
    }
}
1

1 Answers

0
votes

Annotate Invoice with @Document (in spring-mongo)

Also, an id will be required with invoice.

It will store all the fields of Invoice in a JSON format, including the map.