I have a collection of documents like this in a mongo db :
\"_id\" : ObjectId(\"592bc37c339e7a23788b4c7c\"),
\"trips\" : [
{
\"tripGcsId\" : \"5937f
You need to use $pull
update operator which takes the query to match and delete all the matching rows in embedded array.
Something like
public List removeTripObject( List tripIds ) {
Query query = Query.query( Criteria.where( "tripGcsId" ).in( tripIds ) );
Update update = new Update().pull("trips", query );
getMongoTemplate().updateMulti( new Query(), update, "ORDER" );
return updatedOrders;
}
Reference
https://docs.mongodb.com/manual/reference/operator/update/pull/#remove-items-from-an-array-of-documents