moinism/faltu

Fails for {$ne: null}

ben-pr-p opened this issue · 3 comments

Love the library idea. Boundary case!

Doesn't handle {$ne: null} properly.

const data = [{prop: null}, {prop: 'hi'}]
const f = new Faltu(data)
console.log(f.find({prop: {$ne: null}}).get().length)
// logs 0

I believe it's this line, not sure:
https://github.com/moinism/faltu/blob/master/src/faltu.js#L101

Is there another recommended way to check for a property not equaling null?

It also doesn't work for {$eq: null}.

Support for the $and operator would be a workaround (and a nice feature) - then a query of

{$and: [
  {$lt: ''},
  {$gt: ''}
]}

would work.

Depending on my availability I may be able to do this

I was able to get {prop: {$eq: null}} to work by doing {prop: [null]}, so I'm happy.

Not sure if this is a use-case you're interested in supporting.

Glad to see that you've found a way. One workaround for the {$ne: null} problem would be to use filter.

Like:

console.log(f.find().filter(function (item) {
  return item.prop != null;
}).get().length)

You can do the same with $eq too. I'll try to fix these though.

Also, we'd love it if you could add the $and operator.