0

我试图显示 mongodb 服务器的集合,但在 MongoController 类中很难在 FindIterable 中找到集合。我相信这可能是语法错误,但我不明白出了什么问题。

MongoController 类


import com.mongoDB.MongoDAO;
import org.bson.Document;

import com.mongodb.client.FindIterable;

public class MongoController {


    FindIterable<Document> mondgoDB = collection.find();


      for (Document d : users) {
        System.out.println(d.toJson());
      }

      mongoClient.close();

}

}

MongoDAO 类

package com.mongoDB;

import org.bson.Document;
import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;

public class MongoDAO {

    String mongoDB = "storeHeadOfficeDB";
    String mongoCollection = "storeHeadOffice";


    public MongoDAO() throws Exception {
        MongoClient mongoClient = new MongoClient();
        MongoDatabase database = mongoClient.getDatabase(mongoDB);
        MongoCollection collection = database.getCollection(mongoCollection);
    }
}


4

1 回答 1

1
mondgoDB = dbname.collection.find()
于 2019-12-10T05:10:12.613 回答