【问题标题】:insert a new document from querying combined collection从查询组合集合中插入新文档
【发布时间】:2015-12-27 13:51:41
【问题描述】:

我是 Nosql 世界和流星的新手,我有两个集合,taskCollectioin 和workerCollection,我的目标是将每个任务与workerCollection 中的可用时间段相匹配。我的任务集合有字段 {client,task-name,time-flag,assigned=false},我的工人集合有字段 {name, timeslot:[slot, available]}。我还创建了一个名为 matchCollection 结果的结果集合,它需要插入一个文档,从而将每个任务与可用的工作人员匹配。

我的问题:由于我们正在处理来自两个不同集合的查询并比较它们的字段以进行匹配,您将如何在流星中实现一个函数来解决以下伪代码算法?

'FOR each task FROM TaskCollection
   | IF (assigned == false)
   |  |  get the task flag(for example: 10-12 pm)     
   | ENDIF   
   |  FOR each worker From collection
   |  |  **get worker slots
   |  |    IF (worker timeslot is availible for a given task time-flag)
   |  |    |   1-assign the task to the worker
   |  |    |   2-set the task assigned to true
   |  |    |   3-set the timeslot.available to false
   |  |    |   4-create a document in MatchCollection
   |  |    END IF 
   |  ENDFOR     
   ENDFOR'

【问题讨论】:

  • 嘿,你可以用聚合来做到这一点,你已经读过了吗?

标签: javascript mongodb meteor


【解决方案1】:

您将使用聚合来实现这一点...here 你必须研究这部分。

【讨论】:

  • 您可以创建聚合或将文档添加到集合中。
猜你喜欢
  • 2019-06-15
  • 1970-01-01
  • 1970-01-01
  • 2011-05-15
  • 2020-07-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-28
相关资源
最近更新 更多