如何在eclipse中使用java Mongo驱动程序3.12.0从MongoDB使用多个字段查询文档

如何在eclipse中使用java Mongo驱动程序3.12.0从MongoDB使用多个字段查询文档,java,mongodb,Java,Mongodb,当使用FindIterable findIT1=custDetails.find(和(eq(“customer.Fname”、“PQR”)、eq(“customer.Lname”、“Mnl”) 我越来越 错误消息为 Exception in thread "main" java.lang.Error: Unresolved compilation problem: The method and(Bson, Bson) is undefined for the type JavaMong

当使用
FindIterable findIT1=custDetails.find(和(eq(“customer.Fname”、“PQR”)、eq(“customer.Lname”、“Mnl”)

我越来越 错误消息为

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    The method and(Bson, Bson) is undefined for the type JavaMongoConnection
无论我在互联网上搜索什么地方,我都会因为使用操作符而得到相同的答案,但为什么它会说它是未声明的呢?
有人能帮忙吗?

连接后,您必须指定要使用的集合。该错误消息表明
custDetails
是一个
JavaMongoConnection
,而不是一个集合

快速入门

建议这样做以获得收藏:

MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
MongoDatabase database = mongoClient.getDatabase("mydb");
MongoCollection<Document> collection = database.getCollection("test");
MongoClient-MongoClient=newmongoclient(“localhost”,27017);
MongoDatabase=mongoClient.getDatabase(“mydb”);
MongoCollection collection=database.getCollection(“测试”);

然后,您应该能够对该集合使用
查找

连接后,必须指定要使用的集合。该错误消息表明
custDetails
是一个
JavaMongoConnection
,而不是一个集合

快速入门

建议这样做以获得收藏:

MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
MongoDatabase database = mongoClient.getDatabase("mydb");
MongoCollection<Document> collection = database.getCollection("test");
MongoClient-MongoClient=newmongoclient(“localhost”,27017);
MongoDatabase=mongoClient.getDatabase(“mydb”);
MongoCollection collection=database.getCollection(“测试”);
然后,您应该能够对该集合使用
查找

是的,在FindTable之前,我已经编写了上述LOC,现在我连接到MongoDB Atlas
MongoClientURI uri=new MongoClientURI(“MongoDB”)+srv://sumitraojha:@cluster0-tkx83.mongodb.net/customer?retryWrites=true&w=majority“;MongoClient MongoClient=新的MongoClient(uri);System.out.println(“与mongoDB的连接已建立”);//MongoDB数据库连接MongoDatabase Database=mongoClient.getDatabase(“客户”)是在FindTable之前,我已经编写了上述LOC,这里我连接到MongoDB Atlas
MongoClientURI uri=new MongoClientURI(“MongoDB”)+srv://sumitraojha:@cluster0-tkx83.mongodb.net/customer?retryWrites=true&w=majority“;MongoClient MongoClient=新的MongoClient(uri);System.out.println(“与mongoDB的连接已建立”);//MongoDB数据库连接MongoDatabase Database=mongoClient.getDatabase(“客户”)