I want to do a post publication routine every 10 minutes of data obtained by API.
The routine of cron and others works perfectly, but the problem comes when I try to get the first article with a date closer to expiration and has not been published or as little as possible.
I have tried to create an incremental field with the times that has been published, update the date of publication, etc; But I can not give with the formula, I always return the same result, the same article.
Schema
"_id": item.ID,
"title": item.title,
"images": [ item.firstImage ],
"url": "none",
"expired": "2017-04-30T22:00:00+03:00",
"lastPublish": "2017-04-30T20:41:02+03:00",
"publish": 0
Code
db.find({}).sort({ 'expired': 1, 'lastPublish': 1 }).limit(1).exec(function(err, doc) {
//db.find({}).sort({ 'publish': 1, 'expired': 1 }).limit(1).exec(function(err, doc) {
db.update({ '_id': doc._id }, { '$set': { 'lastPublish': new Date(), '$inc': { 'publish': 1 } })
});
I need to make a sort of circular queue, post those that expire earlier (they have dates of hours and days of difference) and when it's over, start over. But I always publish the first post and I'm running out of ideas.
I'd better leave for a few hours and retake it later, when I've cleared my mind.
Thanks !
via Anto
No comments:
Post a Comment