Mongoose的callback()参数错误无效

时间:2016-03-21 04:41:52

标签: javascript node.js mongodb mongoose

我有这样的集合(非常简化)......

public class ImplementationTest {

    public init(){
        print("Init called");

    }

    public func echo(request: String){
        print ("Echo called with "+request);
    }


}

对于一个特定的群体,我想找到该群体中所有拥有移动值集(存在)的家庭成员,并取消设置这些移动值。

通过查看其他示例,我已经能够将这些内容拼凑起来......

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

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

运行会生成错误:

  

跟踪:[错误:无效的callback()参数。]

我尝试了几种变体,但这对我来说似乎是最正确的。

1 个答案:

答案 0 :(得分:2)

mongoose模型的.update()签名是:

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

所以当使用promises时,它只是前两个带有可选的&#34;第三个&#34; options。 &#34;第四&#34;将是callback函数,因此错误:

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

太多人阅读"shell" signature,即使使用:

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

已弃用赞成标准&#34;选项&#34;安排一段时间。

始终引用实际适用于您的语言API的方法。

相关问题