Experimenting with mongoDB’s new $lookup feature

Experimenting with mongoDB’s new $lookup feature

To familiarize myself with the new $lookup feature of mongoDB I did some experimenting.

I tried a couple of different document structures and companion aggregation queries. I based my experiment around the idea of having orders that have keys into related items detail documents.

After seeing the results of some of the aggregations at this point (parallel arrays) I felt like either you'll have to do more manipulation with the aggregation framework to get what you are after, or you'll need to write some code. I think I'd rather just write code. Where the result set out of a SQL join seems smooth, for these types of scenarios the $lookup operator just seems clunky.

In an actual implementation I think I would prefer to see a variant of either of the last two types of documents that includes price in the document. Product prices do change. For example, sale prices, promotions, etc.  Include the price in the order and you won't need to use the $lookup.

Use my code below, posted as a gist, as a jumping off point for your own experimenting.

Leave a Reply

Your email address will not be published. Required fields are marked *