e-oj / Fawn

Transactions for MongoDB (See the README)
https://www.npmjs.com/package/fawn
MIT License
486 stars 54 forks source link

Fawn Not updating last two records and not revert back if any error #66

Closed Sathyababuramk closed 6 years ago

Sathyababuramk commented 6 years ago

Hi, i have been using fawn version 2.1.5. Taking two collections one have to save the set of data into db and other collection to match some condition and add push new array in the collection.

For example i have to save 10 records to save and to update in another collection(pushing array into the collection). The problem that i facing was the 10 records saved successfully and only 8 data update in another collection and fawn doesn't throw any error.

Please help me to fix the issue...

e-oj commented 6 years ago

Can you provide a sample of the code?

Sathyababuramk commented 6 years ago

Hi @e-oj ,

var newTask = fawn.Task(); var collection1 = new collection1(); newTask .initModel('collection1', collection1.schema.paths); newTask .save('collection1', collection1);

newTask.initModel('collection2', collection2.schema.paths); newTask.update('collection2',updateCondition,);

newTask.run().then(function(){ }) In this, I was saving the first collection1 and then updating the second collection with some update condition, and then pushing array elements. For example, suppose I have 10 arrays to match condition and push on collection2. if it fails in the sixth condition, it saved the 1 to 5 array in collection2, stop pushing 6 to 10 array, it Doesn't throw any error or revert back.

e-oj commented 6 years ago

Hard to say what the issue might be. Can you post the actual code? Also, you should only use initModel if you're using mongoose and the model hasn't been initialized yet.

e-oj commented 6 years ago

I'll be closing this issue. Feel free to reopen if you encounter any problems.

CriptoGirl commented 5 years ago

I had a number of similar issues with the update, but in the end, the following worked: try { await new Fawn.Task() .update('collection', { _id: mongoose.Types.ObjectId(req.params.id) } , { name: 'test', desc: 'description }) .run({useMongoose: true}); } catch(err) { console.log(err); }