双嵌套数组mongodb中的$ set值

时间:2019-06-24 15:14:25

标签: mongodb mongodb-query

问题范围

我正在构建工作跟踪器,并且希望通过为查询参数提供$setuserId

jobId特定用户的状态。

问题

运行查询时,它返回null且未找到特定用户。我不确定如何构造查询参数,在此先非常感谢您=]

代码

     IndustryPartner.findOneAndUpdate(
          {
            _id: req.user.corporation,
            "bulletin.jobs.jobList._id": req.body.jobId,
            "bulletin.jobs.jobList.applicationList.user": req.body.userId
          },
          {
            $set: {
              "bulletin.jobs.jobList.$.applicationList.status": "Accepted"
            }
          },
          { new: true }
        )

架构

        {bulletin: {
            jobs: {
              numOfJobs: { type: Number, default: 0 },
              jobList: [
                {
                  applicationList: [
                    {
                      user: { type: Schema.Types.ObjectId, ref: "User" },
                      firstName: { type: String, required: true },
                      lastName: { type: String, required: true },
                      avatar: { type: String, required: true },
                      status: {
                        type: String,
                        enum: ["Accepted", "In Review", "Declined"],
                        default: "In Review"
                      }
    ...

测试数据

 "bulletin" : {
        "jobs" : {
            "jobList" : [ 
                {
                    "_id" : ObjectId("5d103be063b3014b08b0599d"),
                    "applicationList" : [ 
                        {
                            "status" : "In Review",
                            "_id" : ObjectId("5d1046cf802a2a59b8013511"),
                            "user" : ObjectId("5c9bf6eb1da18b038ca660b8"),
                            "firstName" : "Luke",
                            "lastName" : "Skywalker",
                            "dateCreated" : ISODate("2019-06-24T03:43:11.455Z")
                        }
                    ],
                    "dateCreated" : ISODate("2019-06-24T02:56:32.252Z")
                }
            ]
        }
    }
}

0 个答案:

没有答案