简体   繁体   English

在嵌套数组中推送数据,猫鼬

[英]Push data inside nested array , mongoose

Please I know its duplicate , but I dont know why my code is not working 请我知道它的重复项 ,但是我不知道为什么我的代码不起作用

exports.addTechnologyPost = function(req, res){


     console.log(req.params.name);
     var query = {
        name: 'testName',
        version: 'testVer',
        note: 'testNote',
        status: true
     };
     console.log( query );
     Project.findOneAndUpdate(
        { name: req.params.name },
        { $push : {"technologies.$.server" : query }  },  {  upsert: true, new: true },   
        function(err, project) {

        })


 }

My Schema 我的架构

..........
technologies:{
    server:[{
        name: String,
        version: Number,
        note: String,
        status: Boolean
    }]
  }
..........

If its correct or any syntax error ? 如果正确或任何语法错误?

Have you tried removing the $ in the push object key? 您是否尝试过删除推送对象键中的$

Project.findOneAndUpdate(
        { name: req.params.name },
        { $push : {"technologies.server" : query }  },  {  upsert: true, new: true },   
        function(err, project) {

        })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM