“不支持在链接数组中回填空值” MongoDB/领域

发布于 2025-01-12 17:11:14 字数 1314 浏览 1 评论 0原文

当我尝试将新项目添加到文档内的数组时,出现此错误。据我所知,项目引用确实存在于 MongoDB 数据库中。

我得到的错误是:

[
  "To resolve this issue please update or replace the document in MongoDB to make sure it abides by the schema.",
  "Change Event Type: update",
  "Namespace: app.CompanyLocation",
  "Partition: dag1f7g7102aecdd3e9467711e",
  "Document ID: ObjectID(\"61f7f74a2aecdd3e9467711f\")",
  "Detailed Error: cannot insert link at index 7 of array at path { table: \"CompanyLocation\", fullPath: \"units\" }, array has 6 elements and backfilling nulls in array of links are not supported",
  "Number of Unsyncable Documents: 1"
]

导致错误的代码是:

 const newUnits = result.Shipment.Units[0].Unit.map(u => u._attributes.UID +  u._attributes.PSN).flat();
  console.log(newUnits);
  if(importResult.success){
  // Lägg till den som inventory på platsen.
  context.services.get("mongodb-atlas")
  .db("app")
  .collection("CompanyLocation")
  .updateOne(
    {
      _id: new BSON.ObjectId(place), 
      _partition: partition}, 
      {
        $push: {
          units: {
            $each: newUnits
          }
          
        }
        
      }
    )
  console.log(newUnits);
}

我的问题是: 可能是什么原因导致此错误?错误信息是什么意思?

when I try to add new items to an array inside a document I get this error. As far as I know, the item references do exist in the MongoDB database.

The error i get is:

[
  "To resolve this issue please update or replace the document in MongoDB to make sure it abides by the schema.",
  "Change Event Type: update",
  "Namespace: app.CompanyLocation",
  "Partition: dag1f7g7102aecdd3e9467711e",
  "Document ID: ObjectID(\"61f7f74a2aecdd3e9467711f\")",
  "Detailed Error: cannot insert link at index 7 of array at path { table: \"CompanyLocation\", fullPath: \"units\" }, array has 6 elements and backfilling nulls in array of links are not supported",
  "Number of Unsyncable Documents: 1"
]

The code causing the error is:

 const newUnits = result.Shipment.Units[0].Unit.map(u => u._attributes.UID +  u._attributes.PSN).flat();
  console.log(newUnits);
  if(importResult.success){
  // Lägg till den som inventory på platsen.
  context.services.get("mongodb-atlas")
  .db("app")
  .collection("CompanyLocation")
  .updateOne(
    {
      _id: new BSON.ObjectId(place), 
      _partition: partition}, 
      {
        $push: {
          units: {
            $each: newUnits
          }
          
        }
        
      }
    )
  console.log(newUnits);
}

My question is: What may be causing this & What does the error message mean?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文