猫鼬怎么推进阵列

时间:2017-12-12 13:26:08

标签: node.js mongodb mongoose

您好我想在critaire3中推送一个新对象,任何理想的方法都可以吗?

模式

 _id:ObjectId,
Teacher:[{
    id:Number,
    nom:String,
    surnom:String,
    password:String,
    cle:String
}]
,
Etudiant:[{
    id:Number,
    nom:String,
    surnom:String,
    matricule:String,
    password:String    
}],

Chef_de_departement:{
    nom:String,
    password:String,
    cle:String
},

Uv:[{
    code:String,
    nom_eng:String,
    cle:String,
    title:String,
    votes:[{
        critaire1:[{
            vote:Number
        }],
         critaire2:[{
            vote:Number
        }],
        critaire3:[{
            vote:Number
        }],
        critaire4:[{
            vote:Number
        }], 
        critaire5:[{
            vote:Number
        }], 
        critaire6:[{
            vote:Number
        }],
         critaire7:[{
            vote:Number
        }],
         critaire8:[{
            vote:Number
        }],
         critaire9:[{
            vote:Number
        }],
         critaire10:[{
            vote:Number
        }],
        critaire11:[{
            vote:Number
        }]

     }]

}]

输出

"status": "success",
    "data": [{
        "_id": "5a2bb6913e97dbac1de25948",
        "__v": 1,
        "Uv": [{
            "code": "Info204",
            "nom_eng": "stanly",
            "cle": "kdkf",
            "title": "algo  and uml",
            "votes": [{
                "critaire11": [],
                "critaire10": [{}],
                "critaire9": [{}],
                "critaire8": [{}],
                "critaire7": [{}],
                "critaire6": [{}],
                "critaire5": [{}],
                "critaire4": [{}],
                "critaire3": [{}],
                "critaire2": [{}],
                "critaire1": [{}]
            }]
        }],

试过

server.put("/add/votes", function(req, res, next) {

UserModel.update({
        _id: myid,
        'Uv.code': "Info204"
    }, {
        $push: {
            'plan.$.votes.$.critaire3': "df"
        }
    }, {
        upsert: true
    }, function(err, model) {
        if (err) {
            helper.failure(res, next, 'Something went wrong while fetching the user from the database', 500);
            return next();
        }

    helper.success(res, next, model.Uv);

});

});

不知道为什么,但它没有通过!

0 个答案:

没有答案