How to make a query in mongo (mongo template) that it returns a result without alterations?
我的mongoDB中只有一个文档。 这是:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | { "_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" ] } |
并返回该文档。
我已经做了一个查询来得到它
1 2 3 4 5 6 7 8 9 10 | 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; |
问题是
〔实施例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | { "_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,按照插入顺序保存密钥