为什么猫鼬删除了我的部分查询 [英] Why is mongoose removing part of my query

查看:54
本文介绍了为什么猫鼬删除了我的部分查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 mongoDB CLI 中有以下查询:

I have the following query which works in the mongoDB CLI:

db.organisations.updateOne({ _id: ObjectId("5f687da23a4dc9071baefd6d")}, {$pull: {courseIds: 
ObjectId("5f687b863a4dc9071baefd6c"), "groups.$[].courseIds": 
ObjectId("5f687b863a4dc9071baefd6c") }})

以下查询是我认为与猫鼬等效的查询:

And the following query which is what I believe to be the mongoose equivalent:

await Organisation.updateOne({_id: "5f687da23a4dc9071baefd6d"},
{$pull: {courseIds: "5f687b863a4dc9071baefd6c", "groups.$[].courseIds": 
"5f687b863a4dc9071baefd6c"}})

使用 mongoose 调试,我可以看到以下 mongoose 转换为的查询删除了我对数组中所有文档的拉操作的整个后半部分.这是为什么?

Using mongoose debugging I can see that the following query which mongoose translates to is removing the entire second half of my pull operation for all documents in the array. Why is this?

organisations.updateOne({ _id: ObjectId("5f687da23a4dc9071baefd6d") }, { '$pull': { 
courseIds: ObjectId("5f687b863a4dc9071baefd6c") } }, {})

推荐答案

事实证明我有一个大笨蛋.我的猫鼬模式不正确.

It turns out I have the big stupid. My mongoose schemas were incorrect.

这篇关于为什么猫鼬删除了我的部分查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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