方法include在mongodb java中未定义
我正在使用MongoDB shell版本3.6.3,并尝试执行以下类型的查询(来自JAVA):方法include在mongodb java中未定义,java,mongodb,Java,Mongodb,我正在使用MongoDB shell版本3.6.3,并尝试执行以下类型的查询(来自JAVA): SELECT _id, ressort, date from sample WHERE ressort != "A". 我的代码是: MongoClient mongo = new MongoClient("localhost", 27017); MongoDatabase database = mongo.getDatabase("local"); MongoCollection<Docum
SELECT _id, ressort, date from sample WHERE ressort != "A".
我的代码是:
MongoClient mongo = new MongoClient("localhost", 27017);
MongoDatabase database = mongo.getDatabase("local");
MongoCollection<Document> collection = database.getCollection("sample");
FindIterable<Document> findIterable = collection.find(ne("ressort","A")).projection(include("ressort", "date"));
MongoClient mongo=新的MongoClient(“localhost”,27017);
MongoDatabase数据库=mongo.getDatabase(“本地”);
MongoCollection collection=database.getCollection(“示例”);
FindTerable FindTerable=集合。查找(ne(“ressort”、“A”))。投影(包括(“ressort”、“date”));
Eclipse给出了一个错误
类型App的方法include(String,String)未定义
怎么办
我已经完成了筛选器的静态导入。include方法是类
com.mongodb.client.model.Projections
中的静态帮助器方法。请再次检查导入
你可以找到所有帮助者的文档。在我的例子中,我必须包括@cbartosiak所说的导入,然后我必须调用Projections前面的静态方法,以被我的ID识别(Eclipse)
MongoClient mongo=新的MongoClient(“localhost”,27017);
MongoDatabase数据库=mongo.getDatabase(“本地”);
MongoCollection collection=database.getCollection(“示例”);
FindTerrable FindTerrable=collection.find(ne(“ressort”,“A”)).projection(Projections.include(“ressort”,“date”));
MongoClient mongo = new MongoClient("localhost", 27017);
MongoDatabase database = mongo.getDatabase("local");
MongoCollection<Document> collection = database.getCollection("sample");
FindIterable<Document> findIterable = collection.find(ne("ressort","A")).projection(Projections.include("ressort", "date"));