简体   繁体   中英

converting mongoDB query to Java (Distinct with sort)

I want to create java code for the below mongoDB query. Since i am new to mongoDB cananyone help on this

db.getCollection('dum_stats').distinct("engineNo").sort();

Here is a sample example for Mongo 3.x version.

MongoClient mongoClient = new MongoClient();
MongoDatabase db  = mongoClient.getDatabase("yourdb")
MongoCollection<Document> collection = db.getCollection("dum_stats");
FindIterable<Document> distinct = collection.distinct("engineNo", Document.class);
distinct.sort(Sorts.descending("engineNo"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM