Dexie.js: Possibility to add exists with where

Created on 4 Jan 2017  路  3Comments  路  Source: dfahlander/Dexie.js

First of all: thank you for Dexie, it's awesome!

where is really powerfull; nevertheless, it could gain from having a method that just tests whether a field exists or not, similarly to Mongo's $exists method.

For instance, when a given property contains an object, it's not possible (at least to my knowledge) to query all objects that have it. equals doesn't allow this.

I often find myself having to create a separate property that I just use to query and another one that actually contains an object with usefull data:

  • proptToSync: {} would contain dirty properties that need to be synced with server,
  • needSync: 'true' to query (btw, couldn't equals support booleans? As I find it weird to write true/false as strings).

Most helpful comment

You could use

db.yourTable.where('property').aboveOrEqual(-Infinity) 

It will find all objects where the property exists and is of any indexable type (number, string, Date or Array). It wouldn't find propertied of type object or boolean though since those types aren't indexable.

All 3 comments

For $exists check out https://github.com/YurySolovyov/dexie-mongoify . It has the operator from what I can tell but I don't know if it does exactly the same an mongodb's $exists.

Equals does not support booleans because indexedDB indexes don't support booleans. Dexie might support booleans in the future. See https://github.com/dfahlander/Dexie.js/issues/427 .

Regarding server synchronization you might want to checkout Dexie.Syncable https://github.com/dfahlander/Dexie.js/tree/master/addons/Dexie.Syncable

You could use

db.yourTable.where('property').aboveOrEqual(-Infinity) 

It will find all objects where the property exists and is of any indexable type (number, string, Date or Array). It wouldn't find propertied of type object or boolean though since those types aren't indexable.

Thank you both for your prompt and detailed answers.

I love the aboveOrEqual trick. I'll sure have a look at mongoofy too. But from what I've seen, the docs seem poor. Okay, that was on the mobile version, I don't know why.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dmlzj picture dmlzj  路  3Comments

ghost picture ghost  路  3Comments

kamleshchandnani picture kamleshchandnani  路  4Comments

acicali picture acicali  路  4Comments

Script47 picture Script47  路  3Comments