First, I'm very new to NoSQL databases so pardon me if I'm using some wrong terminology. I'm using the agendajs module to store reminders in a Mongo database (required). Since all the reminders have the same job name ('send reminder'), and I'm not storing the generated _id in my own relational database, I'm trying to find a specific in the MongoDB by looking up one of the nested properties in the data field, in this case the reminder's UUID that I generate before storing.
This is how I'm trying to get a specific job, but it's not returning anything.
let thisJob = await agenda.jobs({data: {reminder_id: reminderId}});
This is a job's attr value once created in MongoDB
attrs:
{ _id: 5b86be364f8be75149a3c68e,
name: 'send reminder',
data: [Object],
type: 'normal',
priority: 0,
nextRunAt: 2018-08-29T17:15:00.000Z,
lastModifiedBy: null }
The main question is how can I find a job by searching inside the object stored in the data property?
(I can think of other ways to ultimately achieve the goal I'm after, but I prefer something more optimized)
This should do it:
let thisJob = await agenda.jobs({'data.reminder_id': reminderId});