Feature request: method for retrieving all document ids in a collection faster
chris9182 opened this issue · 1 comments
chris9182 commented
Hello!
I am not sure if this is possible, but in our application we need to find all document ids from a collection at startup in a fast way. We currently do this as follows:
List<Integer> indices = new ArrayList<Integer>();
for (Document document : elementCollection.find())
indices.add(Integer.parseInt(document.getId().getIdValue()));
This is quite slow when working with databases larger than 500k documents.
Is there the possibility to have a method that either returns a List<NitriteId>
, an Iterable<NitriteId>
, an Iterator<NitriteId>
or similar which could provide those values faster? e.g. elementCollection.idIterator();
anidotnet commented
Well there is no such method available in NitriteCollection
. But once you get hold of the underlying NitriteMap
, you can easily access all keys.
NitriteMap<NitriteId, Document> nitriteMap = elementCollection.getStore().openMap("<collectionName>", NitriteId.class, Document.class);
Iterable<NitriteId> nitriteIds = nitriteMap.keys();
for (NitriteId nitriteId : nitriteIds) {
System.out.println(nitriteId);
}
Replace <collectionName> with your collection name. Hope this helps.