question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I have a schema like this:

new Schema({
    waitingList: {
        __type__: {
            current: {
                __type__: [{
                    date: {
                        __type__: Date
                    },
                    user: {
                        __type__: ObjectId,
                        ref: "User"
                    },
                }]
            },
            history: {
                __type__: [{
                    date: {
                        __type__: Date
                    },
                    user: {
                        __type__: ObjectId,
                        ref: "User"
                    },
                }]
            }
        }
    },
}, {
    autoIndex: true,
    typeKey: "__type__"
});

So, in essence a sample document looks like this:

{
  waitingList: {
    current: [],
    history: [{date: someDate, user: myUser}],
  }
}

In that case I want to deep populate user, but if I specify the path as "waitingList.history.user". The plugin crashes with error TypeError: Cannot read property 'paths' of undefined at this position: https://github.com/buunguyen/mongoose-deep-populate/blob/0080a0949fef38bcb9541b267a55810c14c78d4c/lib/plugin.js#L260

For some funny reason I am restricted from declaring sub-schema for those embeded documents. It is possible to make it work in such case?

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Yuliang-Leecommented, Jun 22, 2016

Is this has solution?My code has same problems if key was named “type”.

0reactions
Yuliang-Leecommented, Jun 23, 2016

@kevinresol I try to modify typeKey but deep-populate occurs error

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nested Objects - Learn JavaScript - Codecademy
In application code, objects are often nested— an object might have another object as a property which in turn could have a property...
Read more >
Nested objects in javascript, best practices - Stack Overflow
I would like to know the correct way to create a nested object in javascript. I want a base object called "defaultsettings".
Read more >
JSON nested objects - IBM
Objects can be nested inside other objects. Each nested object must have a unique access path. The same field name can occur in...
Read more >
How to use Nested Objects in JavaScript - Linux Hint
In JavaScript, nested objects are used to store the properties of an object in another object. These objects are accessible via dot or...
Read more >
Accessing Nested Objects in JavaScript - HackerNoon
Array reduce method is very powerful and it can be used to safely access nested objects. const getNestedObject = (nestedObj, pathArr) => { ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found