从查询组合集合插入一个新文档

insert a new document from querying combined collection

本文关键字:一个 新文档 文档 查询 组合 集合 插入      更新时间:2023-09-26

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

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

'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'

您将使用聚合…在这里你必须研究这部分。