'distinct' MongoDB function in java program

481 views Asked by At

I am pretty new to mongo db, and I have a simple question regarding a trouble I can’t solve in my Java program (3.0.2 client version). My aim is to perform a distinct on the “cars” test database, and I am trying this code:

DistinctIterable<Object> classification = collection.distinct("classification", null);

I can’t figure out what should I put in the second parameter. Could you help me please?

2

There are 2 answers

0
Eylen On

If you are using the Java API, I think that you can pass just the first argument, that would be the one on which do the distinct. The second parameter would be the query to filter on, but it can be omitted according to the documentation.

public List distinct(String fieldName)

Find the distinct values for a specified field across a collection and returns the results in an array.

Parameters: fieldName - Specifies the field for which to return the distinct values.

Returns: a List of the distinct values

0
James Baker On