![](/img/trans.png)
[英]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.