MongoDB aggregation $unwind and 1NF

I have a basic rhetorical/theoretical question for people experienced using both MongoDB and RDBMS. Surprised SO has no Data Munging or Data Engineering forum.

In making an aggregation pipeline in Mongo, we use $unwind to explode nested array values so each has its own document so that we may group or do other aggregation.

To me this smells just like getting the data to First Normal Form. The documents tend to look just like records in 1NF at this stage. It seems like that is the goal. I have searched and searched and not found that phrase uttered in any Mongo topics, certainly it was not said in courses I took in MongoDB University. And this would apply to other non-relational data systems as well.

Is 1NF essentially the same thing as the data form necessary for an aggregation step? Is there any data manipulation term for it?

Hi @Bates_Bates and welcome in the MongoDB Community :muscle: !

I’m gonna try an answer. Might not be the ultimate answer but… Let’s try.

$unwind is one way to work with an array in an aggregation pipeline and, for sure, it’s not the most efficient way at all. There are actually many other array operators that you can use to transform or work with an array in an aggregation pipeline.

If there is a smarter way to get the same result without using $unwind + $group on that array, then this is most probably a better solution than this temporary “1NF” that multiplies the number of documents in your pipeline.

Cheers,
Maxime.

1 Like