Database

[{"Id":"Store1","Info":{"Location":"Store1 Street","PhoneNumber":111},"MaxItemsPerShelf":3,"Shelf":[{"Id":"Shelf1","Items":[{"Id":"Item1","Name":"bananas"},{"Id":"Item2","Name":"apples"},{"Id":"Item3","Name":"oranges"}]},{"Id":"Shelf2","Items":[{"Id":"Item4","Name":"cookies"},{"Id":"Item5","Name":"chocolate"}]},{"Id":"Shelf3","Items":[]}]},{"Id":"Store3","Info":{"Location":"Store2 Street","PhoneNumber":222},"MaxItemsPerShelf":2,"Shelf":[{"Id":"Shelf4","Items":[{"Id":"Item6","Name":"champoo"},{"Id":"Item7","Name":"toothpaste"}]},{"Id":"Shelf5","Items":[{"Id":"Item8","Name":"chicken"}]}]}]

Query

db.collection.aggregate([{"$replaceRoot":{"newRoot":{"$let":{"vars":{"shelf":{"$filter":{"input":{"$map":{"input":"$Shelf","in":{"Id":"$$this.Id","count":{"$size":"$$this.Items"}}}},"as":"ss","cond":{"$eq":["$$ss.Id","Shelf2"]}}}},"in":{"Info":"$Info","ItemsNumber":{"$arrayElemAt":["$$shelf.count",0]},"ItemsRemaining":{"$subtract":["$MaxItemsPerShelf",{"$ifNull":[{"$arrayElemAt":["$$shelf.count",0]},0]}]}}}}}}])

Result