I have an array defined in mongoose. In that array there are some fields and one array. All those fields are filled except the array which empty. Now I want to push the new elements into that array. Below is the syntax in mongoose:
{
"_id" : ObjectId("5f426fb0c4057b2ae87e6a8c"),
"hash" : "1cdde2c528d9ac6770d1cb735e89f57b99bf0bc442269013f9df492ea9a2b70ee88c1220a71ac31c650c1cda42573ef9c2f452d572d99866e8a1bd7ed5ea439a",
"salt" : "677468d92cff400e39ed4ad484be3fb8",
"tag" : "Client",
"email" : "vikas.zv95@gmail.com",
"name" : "Vikas Yadav",
"Addtasks" : [
{
"commonID" : "2iwxtrwnap9",
"status" : "Done",
"Date" : "Sun Aug 23 2020 19:02:08 GMT+0530 (India Standard Time)",
"exampleRadios" : "option1",
"otherdetails" : "Not much thanks!",
"website" : "dsfdd.com",
"keywords" : "article importance, article generation, article quality",
"words" : 12345,
"topic" : "How article is generated?",
"_id" : ObjectId("5f426fd8c4057b2ae87e6a90"),
"Bigpaths" : [
]
},
{
"commonID" : "xtcsrnfbvg",
"status" : "Done",
"Date" : "Sun Aug 23 2020 19:02:31 GMT+0530 (India Standard Time)",
"exampleRadios" : "option1",
"otherdetails" : "haha great!",
"website" : "grumpytext.com",
"keywords" : "anxiety disorders for children, anxiety disorders for adults",
"words" : 2345,
"topic" : "How to fight anxiety?",
"_id" : ObjectId("5f426fefc4057b2ae87e6a94"),
"Bigpaths" : [
]
}
],
"__v" : 0
}
I want to push only Bigpaths array of Addtasks array only this time. below is my code I am trying:
var filesArray = req.files;
var Bigpaths2 = [];
filesArray.forEach(element => {
paths = {
"path": element.path,
"name": element.filename
};
Bigpaths2.push(paths);
});
User.updateMany({'Addtasks.commonID':cid}, {$push: {Addtasks.Bigpaths: Bigpaths2}},
function (error, WriterData) {
if (error) {
console.log("error");
} else {
console.log("Task added for the writer.")
}
});
I am getting this error:
\Desktop\grumpytext\routes\index.js:254
User.updateMany({'Addtasks.commonID':cid}, {$push: {Addtasks.Bigpaths: B
igpaths2}},
^
SyntaxError: Unexpected token '.'