如何从mongoose文档中删除指定的字段? [英] How can i remove a specified field from a mongoose document?

查看:766
本文介绍了如何从mongoose文档中删除指定的字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从猫鼬文档中动态删除一个字段/



我尝试过:



我正在使用

 $ unset 

当我输入值

cars.BMW
 {$ unset:{  cars。 +品牌:  }} 

但加号是意外的。

我们非常感谢您的帮助!

解决方案

unset

当我输入值

cars.BMW

它有效。但是,当我想传递一个参数,这将是一个汽车品牌然后取消它。我试过

 {


unset:{ 汽车。 +品牌: }}

但是加号是意外的。

我们非常感谢您的帮助!


I would like to remove dynamically a field from a mongoose document/

What I have tried:

I am using

$unset

and when I type the value

"cars.BMW"

it works. But when I want to pass a parameter, which will be a car brand and then to unset it. I tried

{$unset: {"cars."+brand: " "}}

but the plus sign is unexpected.
Your help will be much appreciated!

解决方案

unset

and when I type the value

"cars.BMW"

it works. But when I want to pass a parameter, which will be a car brand and then to unset it. I tried

{


unset: {"cars."+brand: " "}}

but the plus sign is unexpected.
Your help will be much appreciated!


这篇关于如何从mongoose文档中删除指定的字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆