fakemongo / fongo

faked out in-memory mongo for java
Apache License 2.0
523 stars 155 forks source link

FongoData can't use $comment modifier in count and aggregation operations. #336

Closed lucasoares closed 2 years ago

lucasoares commented 6 years ago

I started to use the $comment modifier in count operations with my DAO.

Since I use Fongo to mock my DAO, the Fongo started to use count commands with this kind of modifier too.

My unit tests reported that this query are returning a wrong result using Fongo: Assert.assertEquals(17, mongoInstance.count(COLLECTION, dbQuery));

This mongoInstance is a instance of my DAO and will only execute this kind of command:

try {
    return getMongoCollection(collection).count(dbQuery.append("$comment", "Comment for this query");
} finally {
    dbQuery.remove("$comment");
}

The same $comment are added to cursor modifier on find operations and this are working fine. But count doesn't have a cursor to set modifiers and we need to use the $comment annotation (MongoDB Documentation). This same issue will make aggregation operations not work, because this kind of operation need to add $comment inside the $match pipeline stage.

I also have a test using a local instance of MongoDB. For the original instance of MongoDB all results are OK and the $comment modifier works fine in every kind of operation.

A link to the MongoDB Documentation reggards to $comment modifier: https://docs.mongodb.com/v3.2/reference/operator/query/comment/

This link is about MongoDB version 3.2, since we use Fongo version 2.1.0 with MongoDB default version 3.2.

lucasoares commented 6 years ago

I will be editing FongoConnection.java to remove $comment from all commands and also the Aggregator.java to remove $comment from all stages of the pipeline until we have some fix about this. This fix will make the Fongo compatible for commands using $comment modifiers but will exclude the feature itself.

lucasoares commented 2 years ago

Using testcontainers now. Closing this issue.