erikolson186 / zangodb

MongoDB-like interface for HTML5 IndexedDB
https://erikolson186.github.io/zangodb/
MIT License
1.07k stars 72 forks source link

Custom query filter #23

Open ajitk opened 7 years ago

ajitk commented 7 years ago

First of all, thank you for such an amazing library. It has been of a tremendous help for us at distill.io when we needed to transition from SQLite to tIndexedDB to build our Firefox web extension.

There is a type of find query that we are not able to use ZangoDB. In this query, one needs to compare one field with another. For example price > threshold. Is there a way to perform such queries?

In general, can one use a function that can perform arbitrary operation in JavaScript and return a boolean value to filter records? Such an API can enable a wide range of queries that may not be possible at this moment.

Thoughts?

erikolson186 commented 7 years ago

I am glad you like ZangoDB and find it useful for your neat project.

It is currently possible to perform your example query:

col
    .find()
    .project({ diff: { $subtract: ['$price', '$threshold'] } })
    .filter({ diff: { $gt: 0 } })
    .project({ diff: 0 })
    .forEach(doc => console.log(doc));

I will look into implementing the $where operator though.

ajitk commented 7 years ago

Thanks for the solution to the example query! Support for $where would be very powerful.