$push to specific field

hello
i am trying to push a item to my nasted array and its not working!
i am trying with the $ operator but this dont work as well
if i put decibelHistory.$.number i get error that says :
“MongoServerError: Plan executor error during findAndModify :: caused by :: The positional operator did not find the match needed from the query.”

but if i will write : decibelHistory$.test
if will not give me this error but it will not update as well
i will upload also my image of the db
Screenshot_139

  const addArrDecibelHistory = async (body) => {
    const userToFetch = await user.findOneAndUpdate(
      { username: 'lior', password:'lior' },
      
      { $push: {'decibelHistory.$.test': {number : 6} } },
   
    );
  };

Hi @Lior_aharon and welcome to the MongoDB community forum!!

Based on the above dataset shared, I tried to replicate the query in my local environment.

Here is how my dataset and the update query looks like:

Atlas atlas-b8d6l3-shard-0 [primary] test> db.collection.find()
[
  {
    _id: ObjectId("63c5af9244361187c0ee7b37"),
    username: 'lior',
    password: 'lior.a98',
    decibleHistory: [ { test: [ '' ] } ],
    timelapse: Long("1200"),
    __v: 0
  }
]
Atlas atlas-b8d6l3-shard-0 [primary] test> db.collection.updateOne( { username: 'lior', "decibleHistory.test": { $exists: true }}, { $push: { "decibleHistory.$.test": { $each: [ { number: 6}], $position: 0}} } )

The output for the above query would be the following:

Atlas atlas-b8d6l3-shard-0 [primary] test> db.collection.find()
[
  {
    _id: ObjectId("63c5af9244361187c0ee7b37"),
    username: 'lior',
    password: 'lior.a98',
    decibleHistory: [
      { test: [ { number: 6 }, '' ] }
    ],
    timelapse: Long("1200"),
    __v: 0
  }
]

Could you check if the above query works for you? If not, could you show us what’s the end result should be?

Let us know if you have any further queries.

Best Regards
Aasawari