CNode

哪位大侠来帮我看看这个问题

问答
Ssw-wang发布于11 年前最后回复11 年前1 回复4243 浏览0 收藏

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)

P
pfcoder#1·11 年前

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

参与回复
登录后即可参与回复。登录