How update data locally??
kawasaki23Ven opened this issue · 5 comments
kawasaki23Ven commented
I need update data locally, im using upsert function but the new data is saved in base and the old in doc...
$rootScope.IndexedDb[database].findOne({_id: data['_id']}, {}, function (res) {
if (res === null) {
$rootScope.IndexedDb[database].upsert(data, function () { });
}
else {
if (angular.equals(res, data) == false){
$rootScope.IndexedDb[database].upsert(res, data, function (data_upserted) {
console.log(data_upserted);
});
}
}
});
grassick commented
You're using the upsert command wrong:
$rootScope.IndexedDb[database].upsert(data, function (data_upserted) {
console.log(data_upserted);
});
Or, if you want to specify the base for some reason:
$rootScope.IndexedDb[database].upsert(data, res, function (data_upserted) {
console.log(data_upserted);
});
In fact, the entire command could just be:
$rootScope.IndexedDb[database].upsert(data, function () { });
Unless you absolutely need to print out the console.log when upserted!
kawasaki23Ven commented
Can you give me an example of how to update a doc?? I did not understand your explanation...
elpollo12 commented
I have the same question of @kawasaki23Ven . I could not do an update.
grassick commented
Sure:
Assuming you have a doc already stored: { _id: "abc", x: 1 }
And you want to update it to { _id: "abc", x: 2 }
Just do this:
db.mycollection.upsert({ _id: "abc", x: 2 }, function() { alert("DONE!") }, function() { alert("ERROR!") })
kawasaki23Ven commented
@grassick It works!!! Thank u so much!!!