JackAdams / meteor-transactions

App level transactions for Meteor + Mongo
http://transactions.taonova.com/
MIT License
113 stars 16 forks source link

Is there a way to use this package with an existing data #54

Closed aksarben09 closed 8 years ago

aksarben09 commented 8 years ago

I suppose the best way of using this package is to use it from the beginning. But I already have data in the database and I would like to integrate this package.

When I try to do this, in particular, to update two documents, I got an error:

No document found. Make sure you provide an _id field for a document that exists. You passed: {"_str":"54c6b04c523e1f182e006a9b"}

The code I used to update looks like this:

tx.start('update');
if (Tags.update(doc1._id, modifier1, {tx: true}) !== 1) {
      throw new Error('Database update failed');
}
if (Tags.update(doc2._id, modifier2, {tx: true}) !== 1) {
      throw new Error('Database update failed');
}
tx.commit();

When I took a closer look, I found that this package does not use ObjectId for _id field but a plain string. This seems to cause the problem. What was the purpose of doing this? Is there a way that I can use this package with existing data without modifying them?

JackAdams commented 8 years ago

Yes, unfortunately this package has no support for anything but string _id values. It was only ever designed with string _id values in mind, as that's what Meteor generally uses. There's no way to use this package with native Mongo object _id values - it would need quite a substantial refactor first.

aksarben09 commented 8 years ago

Thank you @JackAdams for clarifying. I think I can try passing in the ObjectId into update by wrapping it around: {_id: doc._id}.

Closing the issue.