【问题标题】:Removing an element from the array in MongoDB through mongoose通过猫鼬从MongoDB中的数组中删除一个元素
【发布时间】:2022-08-02 17:09:07
【问题描述】:

我将 MongoDB 模型定义为: enter image description here

每个 rToken 都是独一无二的。我想从用户在请求正文中指定的 rToken 数组中删除一个元素,因此,我在下面创建了一个路由: enter image description here

但它没有删除元素,我仍然获得 204 状态。请帮忙。

  • 请不要以图像的形式提供源代码,而应以文本的形式提供。

标签: node.js mongodb mongoose


【解决方案1】:

如果 rToken 是一个数组,您可以删除这样的元素,假设您删除了密码密钥:

const { password, ...rTokenWithoutPassword } = rToken;

然后使用 rTokenWithoutPassword 做任何事情。

如果要删除多个密钥、盐和密码,例如:

const { password, salt, ...rTokenWithoutPassword } = rToken;

【讨论】:

    猜你喜欢
    • 2021-06-14
    • 2018-05-28
    • 1970-01-01
    • 2020-06-10
    • 1970-01-01
    • 2019-09-04
    • 2016-04-03
    • 2021-09-03
    • 2018-11-08
    相关资源
    最近更新 更多