"MongoDB append to document array (moved from Getting Started section)"

mrmikevmrmikev MemberPosts:13Contributor I
edited June 2019 inHelp
I'm attempting to add an item to an array within a document in MongoDB. For example, here's the initial document.

{
"_id" : ObjectId("55bfa1619b527d2ffb37439e"),
"modelName": "Model Sample A1",
"modelResults" : [
{
"resultID" : "1",
"name" : "Result 1 Name",
"resultStuff" : "1000"
},
{
"resultID" : "2",
"name" : "Result 2 Name",
"resultStuff" : "2000"
},
{
"resultID" : "3",
"name" : "Result 3 Name",
"resultStuff" : "3000"
},
{
"resultID" : "4",
"name" : "Result 4 Name",
"resultStuff" : "4000"
}
]
}
I want to add this item to the modelResults array:

{
"resultID" : "6",
"name" : "Result 6 Name",
"resultStuff" : "6000"
}
The command in MongoDB (outside of RapidMiner) would be:

db.mvstuff.update({modelName:"Model Sample A1"},{$push : {modelResults : {
"resultID" : "6",
"name" : "Result 6 Name",
"resultStuff" : "6000"
} }})
I want the result to look like this without having to read in the entire modelResults array and append the new item to it in RapidMiner and write the entire modelResults array back to MongoDB.:
{
"_id" : ObjectId("55bfa1619b527d2ffb37439e"),
"modelName": "Model Sample A1",
"modelResults" : [
{
"resultID" : "1",
"name" : "Result 1 Name",
"resultStuff" : "1000"
},
{
"resultID" : "2",
"name" : "Result 2 Name",
"resultStuff" : "2000"
},
{
"resultID" : "3",
"name" : "Result 3 Name",
"resultStuff" : "3000"
},
{
"resultID" : "4",
"name" : "Result 4 Name",
"resultStuff" : "4000"
},
{
"resultID" : "6",
"name" : "Result 6 Name",
"resultStuff" : "6000"
}
]
}
Here's an example process, but I've not been able to get the desired results:





<宏/ >





<描述一致= "分er" color="transparent" colored="false" width="126">set up criteria






<描述一致= "分er" color="transparent" colored="false" width="126">clean up the result of the previous try










<描述一致= "分er" color="transparent" colored="false" width="126">set up item to add to array








<描述一致= "分er" color="transparent" colored="false" width="126">get the doc to review the results











<描述一致= "分er" color="green" colored="true" height="72" resized="true" width="270" x="496" y="215">insert the initial document



Thanks for your help and comments!

对不起,我不小心和发布这个问题er Getting Started. Problems and Support is more appropriate.
    Sign InorRegisterto comment.