I am a newcomer in mongoDB and this is trying to add an element to an array using push, when I try on the arrays progreso or data_pjs there is no problem I have the problem when I try to insert it on the array datos_progreso
/* 1 */ {
"_id" : ObjectId("5a2a99935887b3f20e1294c6"),
"__v" : 0,
"player" : “Player1”,
"gremio" : "27866",
"progreso" : [
{
"gPowerC" : "2,592,335",
"gPowerS" : "1,594,634",
"fecha" : ISODate("2017-12-07T17:00:21.000Z"),
"_id" : ObjectId("5a2a99935887b3f20e1294c7")
},
{
"gPowerC" : "5,592,335",
"gPowerS" : "5,594,634",
"fecha" : ISODate("2017-12-10T17:00:21.000Z"),
"_id" : ObjectId("5a2aa12cc24daa1417b35107")
}
],
"datos_pjs" : [
{
"name" : "R2-D2",
"_id" : ObjectId("5a2a99935887b3f20e1295cc"),
"datos_progreso" : [
{
"level" : "85",
"gear" : "XII",
"power" : "19,873",
"star" : "7",
"fecha" : ISODate("2017-12-07T17:00:21.000Z"),
"_id" : ObjectId("5a2a99935887b3f20e1295cd")
},
{
/****** HERE ******/
}
]
},
{
"name" : "Jyn Erso",
"_id" : ObjectId("5a2a99935887b3f20e1295ca"),
"datos_progreso" : [
{
"level" : "85",
"gear" : "XII",
"power" : "19,873",
"star" : "7",
"fecha" : ISODate("2017-12-07T17:00:21.000Z"),
"_id" : ObjectId("5a2a99935887b3f20e1295cb")
}
]
}
] }
I try to add the element using this command but it does not work, I would push the element in the data_progress matrix in the R2-D2 character and at the same time push REY element to data_pjs, REY push if that works for me. Can the two operations be performed at the same time?
db.getCollection('pruebas').update (
{ "_id" : ObjectId("5a2a99935887b3f20e1294c6") },
{
$push: {
"datos_pjs" : {
"name" : "R2-D2",
"_id" : ObjectId("5a2a99935887b3f20e1295cc"),
"datos_progreso" : {
"level" : "87",
"gear" : "XII",
"power" : "9,873",
"star" : "5",
"fecha" : ISODate("2017-12-07T17:00:21.000Z"),
"_id" : ObjectId()
}
},
"datos_pjs" : {
"name" : "Rey",
"_id" : ObjectId(),
"datos_progreso" : {
"level" : "85",
"gear" : "XII",
"power" : "9,873",
"star" : "5",
"fecha" : ISODate("2017-12-07T17:00:21.000Z"),
"_id" : ObjectId()
}
}
}
}
)
can anybody help me?