我是mongoDB的新手,这是尝试使用push向数组添加一个元素,当我尝试数组progreso或data_pjs没有问题当我尝试将其插入数组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")
}
]
}
] }
我尝试使用此命令添加元素,但它不起作用,我将推送R2-D2字符中的data_progress矩阵中的元素,同时将REY元素推送到data_pjs,REY push如果适用于我。这两个操作可以同时执行吗?
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()
}
}
}
}
)
任何人都可以帮助我吗?