0

我有一个如下文件(在项目集合中):

      title: "title"
      company: "company"
      companyID: "companyID"
      category: "category"
      starred: false
      createdAt: new Date
      tasks: [
        {
          task:'something'
          completed: false
          taskID: Random.id()
        }
        {
          task:'something'
          completed: false
          taskID: Random.id()
        }
        {
          task:'something'
          completed: false
          taskID: Random.id()
        }
      ]

我可以completed: true使用此方法设置任务:

  completeTask: (projectID, taskID, ifCompleted) ->
    Projects.update {
      _id: projectID
      'tasks.taskID': taskID
    }, $set: 'tasks.$.completed': ifCompleted
    return

如果我将文档更改为:

{
  title: 'title.com'
  company: 'company'
  companyID: Random.id()
  category: 'category'
  starred: false
  createdAt: new Date
  categories: [
      {
        completed: true
        name: 'ideas'
        _id: Random.
        tasks: [
          {task: 'something', completed: false, taskID: Random.id()}
          {task: 'something', completed: false, taskID: Random.id()}
          {task: 'something', completed: false, taskID: Random.id()}
        ]
      }
      {
        completed: false
        name: 'development'
        _id: Random.id()
        tasks: [
          {task: 'something', completed: false, taskID: Random.id()}
          {task: 'something', completed: false, taskID: Random.id()}
          {task: 'something', completed: false, taskID: Random.id()}
        ]
      }
    ]
}

如何设置completed: true任务?

到目前为止我有

completeTask: (projectID, categoryID, taskID, ifCompleted) ->
    Projects.update {
4

0 回答 0