Doing projection operation dynamically to get field from nested documents. Projection from compass is working fine. Aggregation from mongo compass is
{ "itemIds":{ $arrayElemAt: [{ $arrayElemAt: [{ $arrayElemAt: ['$Field1.field2.field3.itemIds',2]},2]},0]} }
trying to get data using mongotemplate as following
ProjectionOperation projection = Aggregation.project().andExpression(Constants.NESTED_CATEGORY_ITEMIDS).as("itemIds").andExclude("_id");
using mongo template getting errors. Can you please suggest correct way to write projection computation using mongo template