失踪儿童

时间:2015-05-05 13:35:42

标签: javascript node.js mongodb mongoose

将Mongoose与MongoDB一起使用,我的架构如下:

var PartSchema = new Schema({
    partcode: String,
    children: [String]
});

数据如下所示:

[{"partcode":"A1","children":["B1","B2","B3","B4"]},
 {"partcode":"B1","children":["C11","C21","C31","C41"]},
 {"partcode":"B3","children":["C13","C23","C33","C43"]},

我可以使用以下静态调用查询A1的子字段:

PartSchema.static('getChildren', function (partcode, callback) {
    var self = this;
    self.findOne({ partcode: partcode }, childrenOnly)
        .exec(function (err, doc) {
        return self.find({"partcode": {"$in": doc.children} }, exclId, callback);
    });
});

返回(通过快递)

 [{"partcode":"B1","children":["C11","C21","C31","C41"]},
 {"partcode":"B3","children":["C13","C23","C33","C43"]}]

我需要的是返回所有未找到的孩子,例如:

[{"children":["B2","B4"}]

0 个答案:

没有答案