How does MongoDB Compass Schema Analyze work?

How would you recreate its result? Does it use aggregation only? Or with some code?

Aggregation pipeline operators like objectToArray doesn’t work with nested key-value. The next easiest way I can think of when dealing with nested key-value is just using the programming language, in my case JavaScript.

What do I have to do in order to get the same result as “analyze” result from “MongoDB Compass > Schema”?