I am currently using "spring-boot-starter-data-mongodb" for persisting documents to a collection in mongodb. The document contains a List with nested objects like:
{
foo:bar,
foos: [
{
foo1: bar1,
foo2: bar2
},
{
foo1: bar4,
foo2: bar3
}
]
}
The mapping of these documents consist the following:
private String foo;
private List<Foo> foos;
Foo:
private String foo1;
private String foo2;
The business logic is heavily depending on the order of the foos (the List elements).
The real questions are:
- Are inserting a document preserves the order of the elements, so that the first item in the list will be the first in the JSON and so on?
- Are querying preserves the order of the elements, so if an element is the N-th member of the document in the DB, will it be the N-th element in the mapped object as well?
Currently it seems to be true but I need to make sure it is guaranteed.