简体   繁体   English

猫鼬无效的callback()参数错误

[英]Invalid callback() argument error with Mongoose

I have a collection like this (very simplified)... 我有一个这样的收藏(非常简化)...

var parentSchema = new mongoose.Schema({
    firstName: String,
    mobile: String
});

var familySchema = new mongoose.Schema({
    groupId: { type: mongoose.Schema.Types.ObjectId, index: true },
    parents: [parentSchema]
});

For a given group, I'd like to find all of the parents of families in that group who have a mobile value set (exists), and unset those mobile values. 对于给定的组,我想找到该组中所有具有移动值集(存在)的家庭的父母,并取消设置那些移动值。

I've been able to piece this much together by looking at other examples... 通过查看其他示例,我已经能够将其整合在一起...

Family.update(
    { groupId: someGroupId, "parents.mobile": {"$exists":"true"} },
    { $unset : { "parents.$.mobile" : 1 } }, false, true
).then(function() {
    // do other stuff
});

Running generates the error: 运行会产生错误:

Trace: [Error: Invalid callback() argument.] 跟踪:[错误:无效的callback()参数。]

I've tried several variations, but this one seems the most correct to me. 我已经尝试了几种变体,但是这对我来说似乎是最正确的。

The .update() signature for mongoose models is: 猫鼬模型的.update()签名为:

Model.update(<{query}>,<{update}>,[<{options}>],[callback])

So when using promises, it's just the first two with the optional "third" options . 因此,在使用Promise时,只有前两个带有可选的“ third” options The "fourth" would be a callback function, and hence the error: “第四”将是一个callback函数,因此会出现错误:

Family.update(
    { "groupId": someGroupId, "parents.mobile": {"$exists": true } },
    { "$unset": { "parents.$.mobile" : "" } },
    { "multi": true }
).then(function() {

Too many people read the "shell" signature , even though the usage of: 即使使用了以下内容,也有太多人看过“ shell”签名

.update(<{query}>,<{update}>,<upsert>,<multi>)

Has been deprecated in favour of the standard "options" arrangement for some time. 已经过时了一段时间,不再支持标准的“选项”安排。

Always refer to the method that actually applies to your language API. 始终参考实际上适用于您的语言API的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM