Database
[{"Id":"12345-7","Stock":[{"Code":"1","Qty":5.0},{"Code":"3","Qty":7.0}]},{"Id":"22222-0","Stock":[{"Code":"3","Qty":10.0},{"Code":"10","Qty":2.0}]}]
Query
db.collection.aggregate([{"$set":{"codes":["1","10"]}},{"$set":{"Stock":{"$reduce":{"input":"$Stock","initialValue":[],"in":{"$cond":[{"$and":[{"$gte":["$$this.Qty",3]},{"$in":["$$this.Code","$codes"]}]},{"$concatArrays":["$$value",["$$this.Code"]]},"$$value"]}}}}},{"$set":{"out-stock":{"$map":{"input":{"$setDifference":["$codes","$Stock"]},"in":{"Id":"$Id","Code":"$$this","Availability":"out of stock"}}}}},{"$set":{"in-stock":{"$map":{"input":"$Stock","in":{"Id":"$Id","Code":"$$this","Availability":"in stock"}}}}},{"$project":{"stock-info":{"$concatArrays":["$out-stock","$in-stock"]}}},{"$unwind":{"path":"$stock-info"}},{"$replaceRoot":{"newRoot":"$stock-info"}}])