可能是版本问题 我使用的是 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> <version>2.1.6.RELEASE</version> </dependency> MongoCollection接口接收得是Bson 不是DBObject FindIterable<TDocument> find(Bson var1); <TResult> FindIterable<TResult> find(Bson var1, Class<TResult> var2); FindIterable<TDocument> find(ClientSession var1); <TResult> FindIterable<TResult> find(ClientSession var1, Class<TResult> var2); FindIterable<TDocument> find(ClientSession var1, Bson var2); <TResult> FindIterable<TResult> find(ClientSession var1, Bson var2, Class<TResult> var3); 例子: MongoCollection<Document> collection = mongoTemplate.getCollection("device"); Bson bson = Filters.in("gatewayImei", gatewayImeis); try (MongoCursor<Document> cursor = collection.find(bson).iterator()) { while (cursor.hasNext()) { Document next = cursor.next(); map.put("imei",next.get("imei").toString()); map.put("gatewayImei",next.get("gatewayImei").toString()); } } return imeis;
awei_mongo 已回答的问题