在我的mapstore中,hazelcast从MongoDB加载所有密钥
@Override
public Iterable<String> loadAllKeys() {
System.out.println("LoadAllKeys");
List<String> keys = new LinkedList<String>();
FindIterable<Document> ids = collection.find().projection(Projections.include("_id"));
for (Document document : ids) {
keys.add(document.get("_id").toString());
}
return keys;
}
当它尝试将这些键作为对象加载时出现问题。它总是给我一个空列表:
@Override
public Map<String, MyObj > loadAll(Collection<String> keys) {
System.out.println("LoadAll " + keys);
HashMap<String, MyObj > result = new HashMap<String, MyObj >();
FindIterable<Document> id = collection.find(in("_id", keys));
for (Document document : id) {
String name = (String) document.get("name");
MyObj myObj= new MyObj();
myObj.setname(name);
result.put(document.get("_id").toString(), myObj);
}
return result;
}
原因是因为我的集合对象_id被ObjectId包装。例如:
"_id" : ObjectId("59b7dac41944ac39f8a299c3")
你能告诉我我哪里错了吗?我用这个链接作为参考:
https://github.com/hazelcast/hazelcast-code-samples/tree/master/hazelcast-integration/mongodb
由于