如何在 mongodb 文档中的数组内创建第二个标识符

发布于 2025-01-12 12:20:33 字数 82 浏览 4 评论 0原文

我正在尝试收集用户, 每个用户都有 MongoDB 的 _id 和姓名、邮件、任务数组和待办事项数组, 我想在数组中为每个任务和待办事项都有一个标识符

I am trying to make a collection of users,
each user has _id of MongoDB and name, mail and array of tasks and array of todos,
I want to have an identifier for each task and todo inside their arrays

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

画骨成沙 2025-01-19 12:20:33

任务和待办事项数组可以是文档数组,因此每个任务和待办事项都可以有一个 id 和一个值:

      {
    "name": "user1",
    "mail": "[email protected]",
    "tasks": [
      {
        "id": "taskId1",
        "task": "taskValue"
      },
      {
        "id": "taskId2",
        "task": "taskValue2"
      }
    ],
    "todos": [
      {
        "id": "todoId1",
        "todo": "todoValue1"
      },
      {
        "id": "todoId2",
        "todo": "todoValue2"
      }
    ]
  }

The arrays of tasks and todos could be an array of documents, so each task and todo could have an id and a value:

      {
    "name": "user1",
    "mail": "[email protected]",
    "tasks": [
      {
        "id": "taskId1",
        "task": "taskValue"
      },
      {
        "id": "taskId2",
        "task": "taskValue2"
      }
    ],
    "todos": [
      {
        "id": "todoId1",
        "todo": "todoValue1"
      },
      {
        "id": "todoId2",
        "todo": "todoValue2"
      }
    ]
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文