feathers-reactive: Official query syntax for $gt, $gte does not work
Steps to reproduce
I got a feathers-reactive service and i want to query some objects that have dates (named start in the example) that are greater then now:
this.someService.find({ query: { $sort: { start: 1 /* sorting works */ }, start: { $gte: moment().startOf('day').toDate() /* this breaks the updates */ } }, rx: { listStrategy: 'always' /* doesn't help */ } }); });
Expected behavior
I’m expecting updates to my subscription
Actual behavior
Initial query works, no updates (created …). Because of the initial query is working fine and because without the $gt on “start” the updates also work i think the issue is in feathers-reactive
System configuration
“feathers”: “^2.1.3”, “feathers-hooks”: “^2.0.1”, “feathers-reactive”: “github:feathersjs/feathers-reactive”, “feathers-rest”: “^1.7.3”, “feathers-socketio”: “^2.0.0”,
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 16 (6 by maintainers)
This is a closed issue, but I just wanted to point out I had difficult time filtering Date Range with nedb. The problem was I was storing Date object inside nedb and when filtering date from Feathers Client it was not working. The cause was Feathers converted the Date object to date string before the Find process, when nedb is expecting Date object. So all I have to do was convert the date string to Date object using before hook and filtering worked. Hope my finding helps people who have similar issue.
Great find @jobobo21 !! Thanks Indeed the date had to be in this format: ‘YYYY-MM-DDTHH:mm:ss[Z]’ and not a standard date object. Strange that every other crud method worked… This should really be documented somewhere, I spend so many days debugging 😄
@h-nasu I’m really tired of all this inconsistency. I’m going another direction and nuking all date objects all together. Instead using ISO date strings, which is what
JSON.stringify
converts them to and are easily converted back in JS.I’ll do it via an application before create hook, then enforce it with ajv validation. I feel like everyone is just using mongoose and letting it deal with these issues.
I ran in to a similar problem with create events (#73 ). With my scenario the value in the query needs to be the right prop type (string, int, float, date, ect…) to be updated on post. I have successfully done a similar gte date query with momentjs ect
start: { $gte: moment().startOf('day').format(/* enter format of date here */)}
Hopefully this helps but I did discover that if your value is in the wrong type the query and most events will work but create will not.