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.

stupid question 2: get key types of nested object in mongoose, not ref/subcollections

See original GitHub issue

Take this example:

@prop({ default: {}, _id: false })
openid: OpenId;

where OpenId is another class like this:

export class OpenId {
    @prop({ index: true, sparse: true, unique: true })
    google?: string;

    @prop({ index: true, sparse: true, unique: true })
    microsoft?: string;

    @prop({ index: true, sparse: true, unique: true })
    apple?: string;
}

But then when for example when trying to update an object with mongoose saying:

 manager.findByIdAndUpdate(_id, {
    openid.google: "something"
});

will throw an error as it doesn’t tell you what keys you have on the “openid” object.

Is it possible to get the types right there without having to work with populating refs/subcollections?

I have worked in the past with proper subcollections & refs and that’s fine for that use case, but sometimes you just need a plain nested object.

Is this supposed to work or am I just doing things wrong?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
smolinaricommented, Jun 18, 2020

For my curiosity, could you offer the actual error message?

Scott

0reactions
hasezoeycommented, Jul 8, 2020

closing because this question seems to be answered

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mongoose: Schema for nested Json and store it (Node.js)
For a nested JSON, you can do something like this: var mongoose =require('mongoose'); var Schema = mongoose.Schema; var standardmessage ...
Read more >
4/4: Using MongooseJS to push objects onto sub-arrays
Let's wrap it up by saving the student events in the database!0:33 Q: what to do without help? A: google it!5:30 why mongoose8:38...
Read more >
How to change the boolean value in nested object - Mongoose
Hello, I want to be able to change the value of a step for goal and step Id that is passed in through...
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