示例对象:
{
name: 'John Doe',
counts: [
{
year: 2018,
month: 7,
count: 138
},
{
year: 2018,
month: 6,
count: 221
}
]
}
在更新子文档数组的对象时,我曾经使用错误代码。如果代码为16836
,则将新对象推入数组。
{
code: 16836,
message: 'The positional operator did not find the match needed from the query'
}
但是,在升级Mongoose和MongoDB之后,它开始无法捕获相关的错误代码。
新的错误对象如下:
{
code: 2,
message: 'The positional operator did not find the match needed from the query'
}
我想知道在代码中使用MongoDB错误代码是否可靠?