簡體   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