derek
derek

Reputation: 10207

guarantee MongoDB update operation is successful

Maybe a dumb question, how to guarantee your update operation is successful? This is how I did it, but the returned "result" is "false".

import { Mongo } from "meteor/mongo";
const Employees = new  Mongo.Collection("Employees");

const result = Employees.update({_id: employeeId}, {$push: {tasks: taskId}});
console.log(result); // "false"

Thanks

Derek

Upvotes: 0

Views: 155

Answers (1)

Kevin Smith
Kevin Smith

Reputation: 14436

All depends what you class as successful? If you take a look at WriteConcern you can get results for acknowledgments, write to journal or writes to a number of nodes with the cluster. This will all depend on your application and how it can deal with failures.

As for getting the number of effected rows you can use the call back on the update method (see the API documentation)

callback Function

Optional. If present, called with an error object as the first argument and, if no error, the number of affected documents as the second.

Upvotes: 1

Related Questions