0

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 ?

1 Answer 1

1

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

        })
Sign up to request clarification or add additional context in comments.

1 Comment

Fixed, I was pushing 'version' data as a string but it should be number

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.