我想从新的Int
数据库中获取MongoDB 3.6.3
。
//Connection
MongoClientURI connectionString = new MongoClientURI("mongodb://localhost:27017");
MongoClient mongoClient = new MongoClient(connectionString);
MongoDatabase database = mongoClient.getDatabase("test");
MongoCollection<Document> collection = database.getCollection("users");
Block<Document> printBlock = new Block<Document>() {
public void apply(final Document document) {
System.out.println(document.toJson());
}
FindIterable<Document> socialList2 = collection.find(eq("id", user_id)).projection(fields(include("social_points"), excludeId()));
socialList2.forEach(printBlock);
mongoClient.close();
它是在控制台中打印想要的数据,但是如何在Java对象中检索数据呢?
它似乎与以前的MongoDB版本不同。