0

I keep getting these 'child' things in my Javascript collection after certain operations. The 'child' keyword is showing up in my terminal after logging the Javascript collection.

Whats strange is that I can't actually find good documentation anywhere online on what this means. Seems like it should be a basic concept.

When I do google it I just get a ton of results for 'child' in context of HTML and the DOM.

What does it mean in javascript? And how could I fix this collection to have these nested collections without the 'child' thing.

Gosh I wish I could speak about it with more sophistication :p

More Context on How This 'Bad' Collection is Generated

So I'm trying to populate JSON data from my Mongodb database and return it to the frontend. Essentially I have nested collections like so:

Institution
 |
  ------------> memberOrganizations
                |
                 ---------------------> associatedVIPs

Where I'm originally grabbing Institutions I can populate collections one level down using built in populate functionality.

Doing like so:

    Institution.find()
        .populate('memberOrganizations')
        .then(function (institutions) {

       console.log("All institutions, memberOrganizations populated no problem.");
        return res.json(institutions);
    });

The problem is coming in when I try to go populate collections inside those member organizations, and replace existing memberOrganizations data with that.

    Institution.find()
        .populate('memberOrganizations')
        .then(function (institutions) {

            var populateOrganizationOrderManagers = _.map(institutions, function (institution) {
                var masterInstitution = _.cloneDeep(institution);
                return new Promise(function (resolve, reject) {
                    var ids = _.map(institution.memberOrganizations, 'id');


         Organization.find(ids).populate('associatedVIPs').then(function (orgs) {

                        masterInstitution.memberOrganizations = orgs;
                        resolve(masterInstitution);
                    });
                });
            });
            return Promise.all(populateOrganizationOrderManagers)
                .then(function (institutionsWithOrderManagers) {
                    return res.json(institutionsWithOrderManagers);
                });
    })

Printouts of the JSON data using console.log to print to my terminal

(Simplified all data by a bit to make it easier to make a point)

What it looks like:

[ child {
  memberOrganizations: 
   [ { associatedVIPs: 
        [ { firstName: 'Gregory',
          lastName: 'Parker',
          email: 'info@parker2018.com',
          id: '5ab94183164475010026184b' } ],
     institution: '5ab940b71644750100261845',
     name: 'Greg Parker',
     type: 'Student',
     id: '5ab941401644750100261847' },
   { associatedVIPs: 
      [ { firstName: 'Irma',
          lastName: 'Francisco',
          email: 'irmaf@houstontransporter.com',
          id: '5ae348da1ef63b245a74fe2d' } ],
     institution: '5ab940b71644750100261845',
     name: 'Transporter Inc',
     type: 'Other',
     id: '5ae3488d1ef63b2c8f74fe29' } ],
      name: 'Corporate',
      createdAt: 2018-03-26T18:49:27.955Z,
      updatedAt: 2018-07-05T15:00:02.562Z,
      id: '5ab940b71644750100261845' }

What I'd like it to look like:

{ memberOrganizations: 
     [ { 
         name: 'Tau Kappa Epsilon',
         type: 'Greek - Fraternity',
         institution: '5a3996d47bab3401001cc1bc',
         id: '5a3ae7ebdfd69201001aa54d'
           associatedVIPs: 
             [ { firstName: 'Irma',
               lastName: 'Francisco',
               email: 'irmaf@houstontransporter.com',
               id: '5ae348da1ef63b245a74fe2d' },
               { firstName: 'Zach',
                 lastName: 'Cook',
                 email: 'zach@google.com',
                 id: '5ae348da1ef63b245a74f' } ]
       },
       { name: 'Farmhouse',
         type: 'Greek - Fraternity',
         institution: '5a3996d47bab3401001cc1bc',
         id: '5a4e71e806b97a01003bd313' } ],
    name: 'Troy University',
    createdAt: '2017-12-19T22:46:44.229Z',
    updatedAt: '2018-07-05T15:18:03.182Z',
    id: '5a3996d47bab3401001cc1bc' },
  { memberOrganizations: 
     [ { name: 'Alpha Epsilon Pi',
         type: 'Greek - Fraternity',
         institution: '5a4d534606b97a01003bd2f1',
         id: '5a4f95c44ec7b6010025d2fb' },
       { name: 'Alpha Delta Chi',
         type: 'Greek - Sorority',
         institution: '5a4d534606b97a01003bd2f1',
         id: '5a74a35e1981ef01001d0633' },
       { name: 'Phi Sigma Kappa',
         type: 'Greek - Fraternity',
         institution: '5a4d534606b97a01003bd2f1',
         id: '5a7ba61821024e0100be67b7' } ],
    name: 'University of Alabama',
    createdAt: '2018-01-03T22:03:50.929Z',
    updatedAt: '2018-07-05T15:18:03.182Z',
    id: '5a4d534606b97a01003bd2f1' }
Zach Cook
  • 604
  • 12
  • 33
  • 3
    It's something the tool which you are using to look at the JS object is putting there. You haven't said what tool that is. – Quentin Jul 05 '18 at 15:30
  • Is it only one object you're trying to edit, or do you need a function to do this to multiple objects? – Alex Jul 05 '18 at 15:31
  • 1
    Where exactly are you getting this, and what is the code that produces this output? – Bergi Jul 05 '18 at 15:31
  • 1
    That value makes is an invalid JS/JSON object...where does this data come from? how are you getting this view? What are you using to look at it, exactly? Like the others, I'd guess some tool or IDE is inserting that into the view. – ADyson Jul 05 '18 at 15:33
  • The data is coming from my API, Nodejs. The view is from my terminal. Gonna put that information into the question real quick. – Zach Cook Jul 05 '18 at 15:39
  • Just added that, thanks @Bergi – Zach Cook Jul 05 '18 at 15:57
  • @Alex I just added more context. hope that helps! – Zach Cook Jul 05 '18 at 15:57
  • @Quentin great point. Its from my terminal after doing a console.log from the nodejs backend environment. That answer your question? – Zach Cook Jul 05 '18 at 15:58
  • @ZachCook I don't see the `console.log` in your code? Anyway, it seems like some annotation added by mongoose, so nothing to worry about. – Bergi Jul 05 '18 at 16:36
  • Btw, avoid the [`Promise` constructor antipattern](https://stackoverflow.com/q/23803743/1048572?What-is-the-promise-construction-antipattern-and-how-to-avoid-it)! – Bergi Jul 05 '18 at 16:36

0 Answers0