### Question:
AbstractMongoDao extends AbstractDao<M,P,K,I> { protected Iterable<M> iterateByQuery(Bson query, Bson sort) { FindIterable<Document> iterable = getCollection().find(query); if (sort != null) { iterable = iterable.sort(sort); } return iterable.map(doc -> getModelMapper().toObject(doc)); } AbstractMongoDao(Class<M> modelClass, Class<P> partialClass, MongoCollection<Document> collection);  AbstractMongoDao(Class<M> modelClass, Class<P> partialClass, MongoCollection<Document> collection, ObjectMapper objectMapper, ObjectMapper extendedJsonMapper);  AbstractMongoDao(Class<M> modelClass, Class<P> partialClass, MongoCollection<Document> collection,
                            DocumentMapper<M> modelMapper, DocumentMapper<P> partialMapper); MongoCollection<Document> getCollection(); String getCollectionName(); DocumentMapper<M> getModelMapper(); DocumentMapper<P> getPartialMapper(); @Override Optional<M> loadOpt(K id); Optional<P> loadOpt(K id, Iterable<String> fields); @Override Iterable<M> iterateAll(); @Override M create(P partial, Instant createAt, I createBy); @Override void update(K id, Update<P> update, Instant updateAt, I updateBy); @Override M updateAndReturn(K id, Update<P> update, Instant updateAt, I updateBy); @Override void delete(K id); @Override void initTable(); @Override void dropTable(); List<IndexModel> getIndexes(); Update<P> updateOf(P object); Update<P> updateOf(P object, Iterable<String> removeFields); static final String ID_FIELD; }### Answer:
@Test public void testIterateByQuery() { dao.create(TestUser.builder().name("Bob 01").active(true).build()); dao.create(TestUser.builder().name("Bob 02").active(true).build()); Iterable<TestUser> iterable = dao.iterateByQuery(new Document("active", true), new Document("name", 1)); Iterator<TestUser> iterator = iterable.iterator(); TestUser user1 = iterator.next(); TestUser user2 = iterator.next(); assertFalse(iterator.hasNext()); assertEquals("Bob 01", user1.getName()); assertEquals("Bob 02", user2.getName()); }