updateAttributes on jugglingdb-redis breaks index for non-string fields

Open Beginner friendly
#349 14 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
65/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
javascript, redis
Domain
databases

Research direction

The bug is in lib/redis.js line 291, where a strict inequality comparison (!==) between a string from prevData and a non-string new value incorrectly triggers index removal. Start by examining the updateAttributes flow, focusing on how prevData is populated via hgetall and how index updates are handled. Verify the fix by modifying the comparison to handle type coercion, then test with a model that has a numeric indexed field to ensure the index persists after an update.

Written by the indexing model from the issue text.

Description

Thank you for all your hard work. I ran into an issue with the jugglingdb-redis adapter. I have several fields that are defined such as:

status: { type: Number, default: 1, index: true }

When I create an instance of the object with that field it saves fine and I can see in the store that there is an index created. However if I call updateAttributes on the same instance later the index actually disappears. I've debugged this and traced it back to the following code: redis.js Line291. It compares the value being saved with the previous value and if they are different it adds the new one and removes the old one. The problem is it uses a !== for comparison so even though you could be passing the same value it will be removed if it is a number, or date or anything but a string. All keys and values in prevData are strings because they come from the hash that was retrieved with a hgetall at line 260. So when you try to do a findOne later on status it fails because it was removed from the index.

Let me know if this makes sense. I'd love to have this working so that I can use numbers, booleans, etc. and still search on them even after updating the records.

Dominant language
JavaScript
Stars
2k
Forks
238
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from 1602/jugglingdb

All issues in 1602/jugglingdb

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.