Index not updated when resource is modified
Closed this issue · 3 comments
From the documentation:
collection.addIndex(string propertyName)
Creates an index for all resources, current and future, in the collection.
and
Note 1: Creating an index is a heavy operation, so it's best done before adding/loading resources into a collection
We have a User
resource and a Session
resource. When creating a Session
, we look up the corresponding userId
by using a users.findOne()
call, looking up the User
resource by the username
for which we have added an index.
However, if we then proceed to modify said User
via REST a PATCH
, we observe that the changes are persisted to our storage, but that the indexes are not updated to reflect the change.
Translated to our real life use case, this means that when we modify a user and change the username and password, the change is persisted, but when we log out and try to log in again using the modified credentials, we get a rested TypeError: Cannot read property 'id' of undefined
as users.findOne() will return undefined
as it cannot find the User
using the modified username. When we kill our app and restart it again, the User
collection and index are loaded from the persisted storage and we can proceed to log in using the modified information.
What is the best workaround or solution for this problem?
So in a nutshell, you're using an ID for a resource that can change over time? That's a problem. Not described in the docs, but too much in the system hinges on IDs not changing. If I got this wrong, please let me know.
I am interested in this error though, especially if it originates in express-rested. Could you provide a stack trace?
Okay, I found your problem. We were not properly re-indexing the resource after a set operation. Fixing it now.
Published under version 1.6.2