Describe the bug
The expected behavior building searches has changed in 1.5
To Reproduce
Steps to reproduce the behavior:
In this code I start with a search on "version". Optionally, I add an "or" criteria. If I add the "or", then the previous "version" search is removed. This code worked correctly in 1.3 and stopped working in 1.5.
Query<C> q = getDatastore().createQuery(_changelogClass);
q.field("version").equal(version);
// POINT A
// id searching
if (param.getDisplayId() != null) {
List<Criteria> orCriteria = new ArrayList<>();
orCriteria.add(q.criteria("adds.id").equal(param.getDisplayId()));
orCriteria.add(q.criteria("deletes.id").equal(param.getDisplayId()));
orCriteria.add(q.criteria("mods.id").equal(param.getDisplayId()));
q.or(orCriteria.toArray(new Criteria[orCriteria.size()]));
}
// POINT B
In the code I am optionally adding an "or" block. I put the string representation of the query object below at two points in both versions
In 1.3.x:
POINT A:
{ query: { "version" : "latest" } }
POINT B:
{
query: {
"version": "latest",
"$or": [{
"adds.id": "5cb5fa6f8d7bd65e8276cd48"
}, {
"deletes.id": "5cb5fa6f8d7bd65e8276cd48"
}, {
"mods.id": "5cb5fa6f8d7bd65e8276cd48"
}]
}
}
In 1.5.0:
POINT A:
{ query: { "version" : "latest" } }
POINT B:
{
{
"$or": [{
"adds.id": "5cb5fa6f8d7bd65e8276cd48"
}, {
"deletes.id": "5cb5fa6f8d7bd65e8276cd48"
}, {
"mods.id": "5cb5fa6f8d7bd65e8276cd48"
}]
}
}
In the new version the "or" overwrites what is in the query, whereas under 1.3 it added an "or" criteria. Is this a known change? I could write this in different ways, but I wanted to highlight that it now produces different results.
I can fix my code by changing it to look like this:
Query<C> q = getDatastore().createQuery(_changelogClass);
List<Criteria> andCriteria = new ArrayList<>();
andCriteria.add(q.criteria("version").equal(version));
// id searching
if (param.getDisplayId() != null) {
andCriteria.add(q.or(
q.criteria("adds.id").equal(param.getDisplayId()),
q.criteria("deletes.id").equal(param.getDisplayId()),
q.criteria("mods.id").equal(param.getDisplayId())
));
}
q.and(andCriteria.toArray(new Criteria[0]));
Describe the bug
The expected behavior building searches has changed in 1.5
To Reproduce
Steps to reproduce the behavior:
In this code I start with a search on "version". Optionally, I add an "or" criteria. If I add the "or", then the previous "version" search is removed. This code worked correctly in 1.3 and stopped working in 1.5.
In the code I am optionally adding an "or" block. I put the string representation of the query object below at two points in both versions
In 1.3.x:
POINT A:
POINT B:
In 1.5.0:
POINT A:
POINT B:
In the new version the "or" overwrites what is in the query, whereas under 1.3 it added an "or" criteria. Is this a known change? I could write this in different ways, but I wanted to highlight that it now produces different results.
I can fix my code by changing it to look like this: