Arrays CastError:对于值';xxx和x27;在路径上“_id";

Arrays CastError:对于值';xxx和x27;在路径上“_id";,arrays,json,mongoose,Arrays,Json,Mongoose,我请求了一个数组,如下所示: { "acceptedBookings": [ { "id": "e1f66d7a852986709f665c3", "Date": "2020-02-04T05:03:25.332Z" } ] } 我想更新每个“id”的“日期”。但是如果我搜索为 等待预订。findById(acceptedBookings[0].id)或 wait Booking.findOne({u id:acceptedBookings[

我请求了一个数组,如下所示:

{
"acceptedBookings": [
    {
        "id": "e1f66d7a852986709f665c3",
        "Date": "2020-02-04T05:03:25.332Z"
    }
  ]
}
我想更新每个“id”的“日期”。但是如果我搜索为

等待预订。findById(acceptedBookings[0].id)

wait Booking.findOne({u id:acceptedBookings[0].id})


它不会给出响应

您访问了错误的成员,您需要的是: 让我们假设您的
地图
类似于

  const acceptedBookings = {
  "accepted": [{
          "id": "e1f66d7a852986709f665c3",
          "Date": "2020-02-04T05:03:25.332Z"
      },
      {
          "id": "i123",
          "Date": "2020-02-04T05:03:25.332Z"
      },
      {
          "id": "i123",
          "Date": "2020-02-04T05:03:25.332Z"
      }
  ]
};

console.log(acceptedBookings.accepted[0].id); // e1f66d7a852986709f665c3
console.log(acceptedBookings.accepted[1].id); // i123

await Booking.findById( acceptedBookings.accepted[0].id ) //should work fine
记住您创建的对象不是
数组
它是
映射/对象
,具有
键:值

因此,首先获得正确的数组/元素,然后访问它的成员

使用
Booking.findOne()
方法的代码更新您的问题