How to add element in nested array in mongodb with java?

Let say that i have this json file :

{
        "_id": "13",
        "firstname": "Hannah",
        "lastname": "Dewalt",
        "phonenumber": 65000091,
        "email": "Hannah@gmail.com",
        "username": "Ha_Dew13",
        "password": "Dewalt",
        "place": "Linz",
        "street": "Wienerstrasse",
        "postcode": 1020,
        "orders": [{
            "_id": 12548,
            "Total Price ": "18974 €",
            "Order Type": "Second_Day",
            "Order Date": {
                "$date": "2021-09-02T22:00:00.000Z"
            },
            "Shipped Time": "3days",
            "Invoice Id ": "4646",
            "items": []
        }, {
            "_id": 12636,
            "Total Price ": "22595 €",
            "Order Type": "Businesse",
            "Order Date": {
                "$date": "2021-08-22T22:00:00.000Z"
            },
            "Shipped Time": "1days",
            "Invoice Id ": "4734",
            "items": []
        }]
    }

and now i want to add multiple elements in item array for specific customer (_id = 13) in specific order where orderid (_id = 12548) .
anyone knows how to do that in java ?

What i want to do is :

"items": ["phone","laptop","smartwatch","tv"]

What i tried :frowning:

Bson firstFilter = Filters.eq("_id", "" + 13);
		Bson secondFilter = Filters.eq("orders._id", "" + 12548);

		this.collection.findOneAndUpdate(Filters.and(firstFilter, secondFilter),
				new Document("$push", new Document("orders.items", "laptop")));
		this.collection.findOneAndUpdate(Filters.and(firstFilter, secondFilter),
				new Document("$push", new Document("orders.items", "phone")));

You have to use positional $ as part of your update operation.

I think orders.$.items rather than order.items. And please do not make 2 updates, $push your 2 values as one operation.

@25gs, was my post useful in solving your issue?

Have you looked at the link I shared?

If my post was useful, please mark it as the solution. This will help keep this forum useful and efficient.