I am using Nodejs backend with MongoDB to hold my object structures with Mongoose as the ORM.
I have a work order object which is following the below pattern. There are thousands of generated work orders and I have a requirement to find the work orders assigned to a given worker on a given date.
Could you help me to come up with a find query?
The query details
- Should be able to query and find itenary - allocated work order - details for a given worker in a given date
- Need to use
allocatedWorker(worker) andallocatedDateTime(date and time) to match and find
Work order object
{
customer: String,
address: String,
/**
* List of to do items. Each item will mainly belong in to a given category
* and a collection of tasks.
* The task can be system generated, admin assigned or customer raised.
*/
todo: [
{
category: String,
/**
* A collection of raised tasks
*/
tasks: [
{
/**
* Holds the customer request details
*/
request: {
workItem: String,
instructions: String,
/**
* Preferred date and time
*/
dateTime: String,
/**
* Preferred worker if any
*/
preferredWorker: String,
receivedDateTime: String
},
/**
* Details of the schedule
*/
schedule: [
{
/**
* Allocated worker's user name
*/
allocatedWorker: String,
allocatedDateTime: String,
allocatedDuration: Number,
/**
* Schedule changed date and time
*/
scheduledOn: String,
/**
* Scheduler's user name
*/
scheduledBy: String,
/**
* Scheduled task status
* 0: Pending - new
* 1: Scheduled - allocated
* 2: Work In Progress
* 3: Completed
* 4: Overdue
*/
itemStatus: Number
}
],
/**
* Stage of the work order
* 0: Pending - new
* 1: Scheduled - allocated
* 2: Work In Progress
* 3: Completed
* 4: Overdue
*/
status: Number
}
]
}
]
}
Workorder.find({$and:[{'todo.tasks.schedule.allocatedWorker': worker}, {'todo.tasks.schedule.allocatedDateTime': day}]}, function(err, orders) {})