How to $push an array consisting of objects having arrays, to an array

I am trying to push something like [ { a:[ ], b: [ ] }, { a:[ ], b: [ ] }, ] inside the array field of the document.

Heres what my mongoose schema looks like-

const GameLogSchema = new Schema({      
    _score: Number,
    _playerData: {
        x: Number,
        y: Number,
    _zoneData: [{ _x: Number, _height: Number }],
    _pipeData: [{ _x: Number, _randomeHeightTop: Number }],
    _gap: Number,

const PlayerSchema = new Schema({
    /* other fields */

    _gameLogs: {
       type: [[GameLogSchema]],  

This is what the data its supposed to deal with looks like -

Spreading one of these objects -

Hello : )

myCollection has one document  {"myarray":[1,2,3]}
if i want to add an element at the end for example the array [{"a":[],"b":[]},{"b":[],"c":[]}]
to get {"myarray":[1,2,3,[{"a":[],"b":[]},{"b":[],"c":[]}]]}
i could update (i use pipeline in the update command => you need mongodb>=4.2)

  "update": "testcoll",
  "updates": [
      "q": {},
      "u": [
          "$addFields": {
            "myarray": {
              "$concatArrays": [
      "multi": true

The above is the database command,you can use your driver update() function,
and take the pipeline only from the command(the “u” value)

If you want to make something like

[1,2,3] to [1,2,3,{"a":[],"b":[]},{"b":[],"c":[]}]

Instead of that in the above code


Use this


Hope it helps

but it has to be this way. Can you suggest a better schema for what I am trying to achieve.
and what I am trying to achieve is insert an array in an array. And I don’t see any other way around it.

Thank you.

Hello : )
Adding an array inside an array (here with $concatArrays the new array will go at the end),its easy to do,the above code,does that.
If you need more help maybe someone can help more about the schema.