Meteor-Community-Packages / ground-db

GroundDB is a thin layer providing Meteor offline database and methods
https://atmospherejs.com/ground/db
MIT License
569 stars 76 forks source link

ground:db@2.0.0-rc.3 can't delete documents #171

Closed JarnoLeConte closed 5 months ago

JarnoLeConte commented 8 years ago

I can't remove documents. I get the following error...

Uncaught (in promise) TypeError: Cannot read property '_id' of undefined(…)   ground.db.js:188
    at http://localhost:3000/packages/ground_db.js:260:42

The pending read/write statistics confirm the failure:

READ 100% done: true
WRITE 0% done: false

If I clear the storage (which works) and insert documents again, the same error occurs when I try to remove them.

edit: I use METEOR@1.3.3 and create a unmanaged collection like new Ground.Collection('something');

hluz commented 8 years ago

@raix Could you look into pulling this and publish?

raix commented 8 years ago

Sorry about the wait @hluz it's vaccation time :) - pr merged and 2.0.0-rc.4 is published Thanks @JarnoLeConte

raix commented 8 years ago

Let me know if this is still an issue in 2.0.0-rc.5

paranoico commented 8 years ago

We are experiencing same problem in 2.0.0-rc6, but in different code line: TypeError: Cannot read property '_id' of undefined(…) TypeError: Cannot read property '_id' of undefined at GroundKonetl.saveDocument (http://localhost:3000/packages/ground_db.js?hash=65466264538f340bd5903bdfa757880bdc26690c:264:26) at GroundKonetl.remove (http://localhost:3000/packages/ground_db.js?hash=65466264538f340bd5903bdfa757880bdc26690c:683:12)

The error arises when trying to remove elements from an empty collection.

So we have changed remove function on ground.db.js from line 439 and validating document before saving it as follows: remove(selector, ...args) { // Order of saveDocument and remove call is not important // when removing a document. (why we don't need carrier for the result) const doc = this._collection.findOne(selector); doc && this.saveDocument(doc, true); return this._collection.remove(selector, ...args); }

@raix could it be included in next release? Or can I make a PR?

raix commented 8 years ago

@paranoico you are wellcome to do a pr. I'm as always a bit low on time

paranoico commented 8 years ago

Pull request done, hope have done it right #188

Thanks a lot @raix