Here is my schema of the collection:
var mongoose = require('mongoose');
var urlSchema = new mongoose.Schema({
url: String,
easeDate: { type: Date, index: 1},
created: { type: Date, default: Date.now }
});
I need to do an update action with the oldest document (by easeDate) to change its easeDate
date to «now + some timeout» and get the affected document. Is it possible in one request?
Basically, I want to make something like a queue from the collection (the "oldest" one is the next one pulled out i.e. first in first out). Deletion of urls (documents in the collection) is done by other conditions. I don't want to delete from queue but put to the end of it by updating easeDate
.
Finally, I want to take the available url and set a timeout to it, so that the next time there was returned the next url. If it was the last url, then null
is returned next time, because of timeout.
And if I can update it so, how can I query the database (mongoose) to get the next url where easeDate < Date.now()? Could you please give an example in JavaScript?