Get names of all keys in the collection and subdocuments

Get names of all keys in the collection and subdocuments

I need to get all the field names from my collection, including fields in subdocuments. I am currently running this command and getting only the names of the root fields. How can I get all field names?

I need to get all the field names from my collection, including fields in subdocuments. I am currently running this command and getting only the names of the root fields. How can I get all field names?

My collection looks like this:

"UserId" : 11111,
"Personal" : {
    "Email" : "[email protected]",
    "FirstName" : "Name",
    "LastName" : "Last"
},
"Car" : {
    "CarType" : "NULL"
}

This is the command

var mr = db.runCommand({
"mapreduce" : "myCollection",
  "map" : function() {
    for (var key in this) { emit(key, null); }
  },
  "reduce" : function(key, stuff) { return null; }, 
  "out": "myCollection" + "_keys"
})

db[mr.result].distinct("_id")

I want this result:

UserId, Personal.Email, Personal.FirstName, Personal.LastName, Car.CarType

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

MongoDB JavaScript tutorial with Examples

MongoDB JavaScript tutorial shows how to do create programs that work with MongoDB in JavaScript. This tutorial uses the native mongodb driver. (There are also other solutions such as Mongoose or Monk.)

JavaScript Tutorial: if-else Statement in JavaScript

This JavaScript tutorial is a step by step guide on JavaScript If Else Statements. Learn how to use If Else in javascript and also JavaScript If Else Statements. if-else Statement in JavaScript. JavaScript's conditional statements: if; if-else; nested-if; if-else-if. These statements allow you to control the flow of your program's execution based upon conditions known only during run time.