1

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)

sb9
  • 266
  • 7
  • 22

1 Answers1

4

This should do it:

let thisJob = await agenda.jobs({'data.reminder_id': reminderId});
Akrion
  • 18,117
  • 1
  • 34
  • 54
  • 1
    Not sure why this got downvoted, it works for me (October 2020). You get an array with all matching jobs. If you use a unique id, it should just be an array with a length of one. – dockleryxk Oct 01 '20 at 19:40