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
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")));