如何在 mongo(mongo 模板)中进行查询,使其 returns 的结果无需更改?

How to make a query in mongo (mongo template) that it returns a result without alterations?

我的 mongoDB 中只有一份文件。这是:

{
"_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"
]
}

和 return 那个文档。

我查询得到了

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;

问题是 configShowable 顺序被改变了,我不需要那个。我需要 return 与数据库中插入的相同,换句话说,创建的地图在 disoreder 中。

示例:

{
"_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"
]
}

我怎样才能预防这种疾病?

我建议你使用 LinkedHashMap ,保持键的插入顺序