繁体   English   中英

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

[英]how to query document using multiple fields from MongoDB using java Mongo driver 3.12.0 in eclipse

使用FindIterable<Document> findIT1 = custDetails.find(and(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

无论我在互联网上搜索的哪个地方,使用运算符都会得到相同的答案,但是为什么它说它是未声明的? 请问有人可以帮忙吗?

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

https://mongodb.github.io/mongo-java-driver/3.4/driver/getting-started/quick-start/#access-a-collection的快速入门

建议这样做来收集:

MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
MongoDatabase database = mongoClient.getDatabase("mydb");
MongoCollection<Document> collection = database.getCollection("test");

然后,您应该能够使用findand与该集合。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM