0

I have a collection of Customer that have multiple Order. The Order is an embedded array in the Customer collection. Inside one Order there is an @ReferencedMany to the Product collection.

I now want to do some reporting on every Product that a Customer has ever bought.

What would be the MongoDB way to find all the products for this customer and add filters on this query. I don't want to loop every order and then fetch all the products and put them in a Doctrine ArrayCollection.

Is there a direct way to query these products?

1 Answer 1

1

Mongo DB does not fetch references automatically in single query. Maybe some drivers support such functionality and may produce sub-query/ies transparent for user.

You can aggregate the data required for report to one collection using map-reduce pattern, for example, or embed Product data to Customer. But as consequence the queries on Product will become more complex.

You can de-normalize data and duplicate some Product data required for reports in Customer collection. Then you'll have to deal with synchronization of those collections.

Working on same issue, I came to the conclusion that if you want to reflect relations between objects you should use relational database :)

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

Comments

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.