Closed kahanu closed 4 years ago
It should work as written in your example, so weird.
When you use const coll = this.db.getCollection(this.collName);
have you tried to see what value that variable contains on the console.log
? Sometimes errors in update is because the getCollection
is null because the db
is not initialized as it hasn't loaded the database (async problems). This happen in Angular do to how Classes work with .this
.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I'm having a problem updating objects in the collection. In my Angular 8 application I've built a LokiService that has all the basic CRUD operations, and so far Update is the one giving me grief. I've looked everywhere for a reliable solution and I haven't found one.
Here is the
put
method of my service:This is the output of the console.log() and the error that appears:
data to be updated: {id: 4, name: "Security Protocols"}
found: {id: 4, name: "Security Protocols Group", meta: {…}, $loki: 8}
found updated: {id: 4, name: "Security Protocols", meta: {…}, $loki: 8}
Everything is correct up to this point, as far as I know, then the Chrome tools displays this error and the update never happens.
Note: for the argument of the
put
method (data to be updated), I can actually return the full LokiJs object with the updated value that includes the$loki
andmeta
properties, but I get the same error as below.I looked at the issue here, https://github.com/techfort/LokiJS/issues/420 and it has an example, that works in the sandbox, but not in Angular.
I tried applying that function, but I get the error that says:
TypeError: Cannot assign to read only property 'id' of object '[object Object]'
Any insight on what I'm doing wrong is appreciated. So at the moment I can do everything except Update.