哪位大侠来帮我看看这个问题
发布于 9 年前 作者 sw-wang 3277 次浏览 最后一次编辑是 8 年前 来自 问答

mongodb数据为: { “id” : ObjectId(“55d42b62676bda1c1c6a09ae”), “name” : “生活”, “description” : “生活需要大爆炸”, “type” : 1, “subtype” : [ ], “v” : 0 }

其数据结构为:

var typeScheMa = new ScheMa({
    name: String,
    description: String,
    type:Number,
    subtype:[{
        name: String,
        description: String,
        type:Number
    }]
});

现在我想新增subtype里面的记录,用mongose应该怎么写呢?

1 回复

Modelxxx.update({/* query condition*/}, {$push:{subtype: {/* new element */}, {/* options, like upsert */}, function(error, result) {});

回到顶部