0

I have only one document in my mongoDB. This is:

{
"_id": "32fqwefr",
"propertyName": "configShowableField",
"Applicant": [
    "R:a_FII",
    "R:a_PN"
],
"Employment": [
    "R:a_FIIq",
    "R:a_PsN"
],
"Product": [
    "R:a_FII",
    "R:a_PN"
],
"Address": [
    "R:a_FII",
    "R:a_PN"
]
}

and returns that document.

I've made a query to get it

Map<String, List<String>> configShowable = new HasMapsh<>();
Query query = new Query();
query.addCirteria(Criteria.where("propertyName").is("configShowableField"));
Map<String. Object> config = getMongoTemplate.findOne(query, Map.class,"Collection");
config.forEach(k,v)->{
if(v instanceof List){
    configShowable.put(k, (List<String>V));
}
}
return configShowable;

The problem is that the configShowable order is altered and I do not need that. I need that I return the same in which was inserted in the data base, in orther words, the Map than was created is in disoreder.

Exmaple:

{
"_id": "32fqwefr",
"propertyName": "configShowableField",
"Address": [
    "R:a_FII",
    "R:a_PN"
],
"Applicant": [
    "R:a_FII",
    "R:a_PN"
],
"Product": [
    "R:a_FII",
    "R:a_PN"
],
"Employment": [
    "R:a_FIIq",
    "R:a_PsN"
]
}

How can I prevent that disorder??

TuGordoBello
  • 4,350
  • 9
  • 52
  • 78
  • possible duplicate of [Java Ordered Map](http://stackoverflow.com/questions/663374/java-ordered-map) – Blakes Seven Sep 15 '15 at 23:43
  • Are you sure the document has the structure you want in mongodb? When you insert it, mongodb should sort it in alphabetical order and ruin your plans long before you ask for a result. – Digits Sep 15 '15 at 23:49
  • @Digits I am sure of that because I've added it manualy – TuGordoBello Sep 16 '15 at 00:08

1 Answers1

0

I suggest you use LinkedHaskMap , keeps the keys in the order they were inserted

Rohit Jain
  • 2,052
  • 17
  • 19