如何从MongoDB接收Int值(新3.6.3)

时间:2018-03-14 14:32:15

标签: java mongodb

我想从新的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版本不同。

0 个答案:

没有答案