javascript - 将数据推送到嵌套数组、 Mongoose 中

标签 javascript node.js express mongoose

我知道它重复,但我不知道为什么我的代码不起作用

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) {

        })


 }

我的架构

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

是否正确或有任何语法错误?

最佳答案

您是否尝试过删除推送对象键中的$

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

        })

关于javascript - 将数据推送到嵌套数组、 Mongoose 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56061790/

相关文章:

javascript - 为什么不跟踪 js 类的 mobx 可观察属性,但跟踪 mobx 可观察对象的属性?

node.js - npm 找不到 package.json

node.js - web3 对象什么时候被注入(inject)到网页中?

javascript - Python/HTML 如何在没有 cookie Advisor 的情况下抓取网页内容?

javascript - REST API Javascript 如何编写检查 SQL 查询是否返回 0 行的条件

javascript - 将图像另存为 Base64 时应用程序在 Ionic View 中崩溃

node.js - Mocha 测试失败,错误来自 "before all"钩子(Hook)

javascript - 当 console.log 返回包含值的数组时,Resolve 返回空数组

javascript - 浏览器窗口中自动转换日期

node.js - (不)将局部变量传递给 Express (node.js) 中的 Jade 模板