question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple similar filters can lose the existing filter

See original GitHub issue

I think there is a bug in the new Morphia 2.2.3. I translated code from Morphia 1.x and the generated MongoDB queries seem to be mixed up when combining .exits() and .not() and that kind of combinations.

// OLD Morphia 1.x WORKED
q.or(q.criteria("disabled").doesNotExist(), q.criteria("disabled").hasThisOne(Boolean.FALSE));

// NEW Morphia 2.x DOES NOT WORK
q.filter(Filters.or(Filters.exists("disabled").not(), Filters.eq("disabled", Boolean.FALSE)));
);

// OLD Morphia 1.4 WORKED
//			q.or(
//					q.criteria("belongsToContentId").doesNotExist(),
//					q.and(
//							q.criteria("belongsToContentId").exists(),               
//							q.criteria("showAtGuideLevel").hasThisOne(Boolean.TRUE)
//					)
//			);

// NEW Morphia 2.x DOES NOT WORK

	q.filter(
			Filters.or(
					Filters.exists("belongsToContentId").not(),
					Filters.and(
						Filters.exists("belongsToContentId"),           
						Filters.eq("showAtGuideLevel", Boolean.TRUE)
					)
			));

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

0reactions
adevvvcommented, Mar 16, 2022

I tried today if the problem is fixed with morphia 2.2.5, but there still seems to be a problem. STEP 1:

final Query<Event> q = dbs.getDatastore().find(Event.class);
q.filter("customerId", customerId);
		q.filter(
				Filters.or(
						Filters.exists("status").not(),
						Filters.eq("status",0
				)
		);
log.info("Q1: " + q);

Q1: MorphiaQuery[clazz=Event, query=Document{{customerId=5ca0c24a4ac35d7748610e68, $or=[Document{{status=Document{{$exists=false}}}}, Document{{status=0}}]}}]

STEP 2:

			q.filter(
					Filters.or(
							Filters.exists("belongsToContentId").not(),
							Filters.and(
								Filters.exists("belongsToContentId"),              
								Filters.eq("showAtGuideLevel", Boolean.TRUE)
							)
					));
log.info("Q2: " + q);

Q2: MorphiaQuery[clazz=Event, query=Document{{customerId=5ca0c24a4ac35d7748610e68, $or=[Document{{belongsToContentId=Document{{$exists=false}}}}, Document{{$and=[Document{{belongsToContentId=Document{{$exists=true}}}}, Document{{showAtGuideLevel=true}}]}}]}}]

BUG: The filter of status from before is gone?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Filter data in a range or table - Microsoft Support
Select Text Filters or Number Filters, and then select a comparison, like Between. Number Filters Between. Enter the filter criteria and select OK....
Read more >
Excel 2013: Filtering Data - GCF Global
Filtering in Excel lets you temporarily hide unwanted data. Use filters in Excel to narrow down data in your Excel spreadsheet.
Read more >
Apply Filters to Multiple Worksheets - Tableau Help
Filters that apply to all related data sources are marked with an icon. The filter is automatically created on any existing worksheets, and...
Read more >
Excel FILTER function with formula examples - Ablebits
See how to filter in Excel dynamically with formulas. Examples to filter duplicates, cells containing certain text, with multiple criteria, ...
Read more >
Excel Filters Training - Multiple Column Filters - Part 3 of 3
You will learn about the rules Excel uses to apply filters with AND logic. I also explain how to filter multiple columns with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found