allenA
Convex Community3y ago
16 replies
allen

undefined < Number === true?

I have an optional expiresAt field in my schema that holds an expiration date for a record. If its undefined, it should never expire. I have an index on this field as I have a cron job running every minute to see what should be expired. That query looks like so:
db
      .query('requests')
      .withIndex('by_expiration', (q) =>
        q.eq('isExpired', false).lte('expiresAt', Date.now()),
      )


However, this returns records that have an undefined value for the expiresAt field, requiring me to filter these in memory with:
.filter((q) => q.neq(q.field('expiresAt'), undefined))


Being this runs so frequently, its eating through my db bandwidth, retrieving these unwanted rows.

Before I get cute with my schema to hack around this...

1) Is this the intended behavior of the query engine? It doesnt match javascript's behavior.
2) Is there a way to better structure or query my existing index to remove these results?
Was this page helpful?