在MongoDB文档集合中查找对象数组中的元素

时间:2016-09-29 23:59:48

标签: node.js mongodb mongoose

我使用Nodejs后端和MongoDB来保存我的对象结构,使用Mongoose作为ORM。

我有一个工作订单对象,它遵循以下模式。有数千个生成的工单,我需要找到在给定日期分配给给定工人的工单。

你能帮我提一下查找查询吗?

查询详情

  1. 应该能够查询和查找itenary - 已分配的工单 - 给定工人在给定日期的详细信息
  2. 需要使用allocatedWorker(工作人员)和allocatedDateTime(日期和时间)来匹配和查找
  3. Work order对象

    {
        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
                    }
                ]
            }
        ]
    }
    

1 个答案:

答案 0 :(得分:1)

尝试以下查询:

  <video id="video-area" controls>
      <source src="videos/person.mp4" type="video/mp4">
  </video>

请记住,两者都将执行存储在db。

中的精确值匹配(确切名称和日期时间)