[英]How to retrieve a random document from a collection using the Mongo Java driver
[英]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
无论我在互联网上搜索的哪个地方,使用和运算符都会得到相同的答案,但是为什么它说它是未声明的? 请问有人可以帮忙吗?
连接后,您必须指定要使用的集合。 该错误消息表明custDetails
是JavaMongoConnection
,而不是集合。
建议这样做来收集:
MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
MongoDatabase database = mongoClient.getDatabase("mydb");
MongoCollection<Document> collection = database.getCollection("test");
然后,您应该能够使用find
和and
与该集合。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.