0

Please consider this as a part of my schema.

newSchema({
   'product':{}
   'productPayment':[{}]
});

productPayment has 'n' number of elements each with unique Ids. I want to return only that array element which matches my id. I queried like schema.findOne({'_id':variables._id,'productPayment._id':variables.productPaymentId}) but it returns whole document, but I want that particular element only. How can I possibly get that? Any help will be appreciated. Thanks in advance.

1 Answer 1

1

Take help from projections, something like this:-

 schema
.findOne({'_id':variables._id,'productPayment._id':variables.productPaymentId})
.select({ productPayment: {$elemMatch: {_id: variables.productPaymentId}}})

*this is just a sample code please modify according to your needs

Sign up to request clarification or add additional context in comments.

2 Comments

what is the Friends here?
Updated answer pls check

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.