Panache Query With Mongo: and operator not working properly with multiple conditions on same field
See original GitHub issueThe following test is failing:
@Test
public void failingQuery() {
UUID videoId = UUID.randomUUID();
LocalDateTime now = LocalDateTime.now();
View view = new View(videoId, now.minusMinutes(10));
view.persist();
long count1 = View.count("createdAt > ?1", now.minusMinutes(2));
logger.info("count 1: {}", count1);
assertThat(count1).isEqualTo(0); // passing
long count2 = View.count("createdAt > ?1 and createdAt < ?2", now.minusMinutes(2), now);
logger.info("count 2: {}", count2);
assertThat(count2).isEqualTo(0); // failing (count2 is equal to 1)
}
I think the corresponding mongo query should be
createdAt: {
$gte: ISODate(date1),
$lt: ISODate(date2)
}
The actual mongo query created by panache is:
{
'createdAt':{'$gt':ISODate('2020-09-14T18:49:36.897Z')},
'createdAt':{'$lt':ISODate('2020-09-14T18:51:36.897Z')}
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:13 (9 by maintainers)
Top Results From Across the Web
Simplified MongoDB with Panache - Quarkus
MongoDB queries must be valid JSON documents, using the same field multiple times in a query is not allowed using PanacheQL as it...
Read more >MongoDB query with multiple conditions - Stack Overflow
Above query work as "OR" condition. I need "AND". i.e. Result only return on exact match of both condition. ... -1 db.getCollection('TheCollection').find({ ' ......
Read more >Update Multiple Fields in a MongoDB Document - Baeldung
In this tutorial, we'll learn to modify the multiple fields of a document using the update and the replace query. For demonstration purposes ......
Read more >$and — MongoDB Manual
AND Queries With Multiple Expressions Specifying the Same Operator ... The query selects all documents where: ... The query cannot use an implicit...
Read more >Simplified MongoDB with Panache - Quarkus
Normally, MongoDB queries are of this form: {'firstname': 'John', 'lastname':'Doe'} , this is what we call MongoDB native queries. You can use them...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@rmanibus so there is an issue, a query must be a valid json document, so if you use multiple condition on a query it must be defined as a sub document (and not defined as multiple times the same field as it is done today).
Today we use a string based query generator, we may need to revisit this to fix this issue.
To workaround this, you can use a native query untill we provide a proper fix:
A fix for this would really come in handy.