Closed AvikSengupta27 closed 7 years ago
orm.TEST.updateAll({ order: 'dateUploaded DESC', Status:'Available', limit:1 }, {Status: 'Blocked'}, function(err, result) { console.log(err + " "+JSON.stringify(result)); });
This code returns me count 0
@AvikSengupta27 Please check our doc about how to use updateAll
: http://loopback.io/doc/en/lb2/Creating-updating-and-deleting-data.html#updating-data-model-instances
And how to use AND
in Where
clause: http://loopback.io/doc/en/lb2/Where-filter.html#and-and-or-operators
I want to update the document where Status is Available and has minimum date.
Does "minimum date" means from all returned records you only need the one with minimum date[scenario 1]? Or it means you already know the minimum date and you want all records that have that date[scenario 2]?
scenario 1:
You can send a query to find the instance whose status is Available
and with min date, then update attribute of that instance:
find({where: {Status: 'Available'}, order: 'date DESC', limit: 1}, function (err, instance) {
// Then only updateAttribute of that instance here:
instance.updateAttribute('Status', 'Blocked', cb);
// about how to use updateAttribute see: http://loopback.io/doc/en/lb2/Creating-updating-and-deleting-data.html#updating-data-model-instances
})
scenario 2:
the first argument of updateAll
should be
{and: [{Status: 'Available'}, {date: minDate()}]}
hi @AvikSengupta27 any updates in this issue? details see https://github.com/strongloop/loopback-connector-cloudant/issues/19#issuecomment-261574497, thanks.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I am closing this issue due to out of date, please feel free to reopen it if you still have problem after follow https://github.com/strongloop/loopback-connector-cloudant/issues/19#issuecomment-261574497, thanks!
I have documents with _id,Status and dateUploaded fields. I want to update the document where Status is Available and has minimum date.
I am able to successfully run the below code, but it updates all the documents where the Status is 'Available'
orm.TEST.updateAll({Status: 'Available'}, {Status: 'Blocked'}, function(err, result) { console.log(err + " "+result); });
The logic I am trying to execute is
orm.TEST.updateAll( {Status: ‘Available’, dateUploaded: logic for min date}, {Status: ‘Blocked’}, function(err, results) { return callback(err, results); });
How to get the minimum date in the where clause ?