My MongoDB documents look something like this:
{
"person_id": 12345,
"first_name": "John",
"last_name": "Doe",
...
}
I now want a query that gives me a Collection<Long>
of person_id
s, with some filters applied. Filtering works fine, but MongoCollection.find
returns a MongoCollection of Documents.
Is there an implicit way to just get the values (12345
), not key-value-pairs ("person_id" : 12345
)?
Right now I'm just filling a new Collection by iterating over the result, extracting the values one by one. If there's no other way to do it, is there any point in using a projection to restrict the returned fields to person_id, or is that just overhead?