Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mongoose Document { undefined } #8565

Closed
aleksandr-gorokhov opened this issue Feb 6, 2020 · 1 comment
Closed

Mongoose Document { undefined } #8565

aleksandr-gorokhov opened this issue Feb 6, 2020 · 1 comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@aleksandr-gorokhov
Copy link

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
Just migrated to mongoose@5.8.11 from mongoose@5.4.4 and Document.set method fails

If the current behavior is a bug, please provide the steps to reproduce.
I have 3 models with schemas like these:

const widgetSessionSchema = new mongoose.Schema({
  plaid: {
    nestedKey: String
  }
})
const subscriptionSchema = new mongoose.Schema({
  plaid: {
    nestedKey: String
  }
})
const chargeSchema = new mongoose.Schema({
  plaid: {
    nestedKey: String
  }
})

when Im trying to inherit plaid into charge document in this way:

// widgetSession could either contain plaid or not
const widgetSession = new WidgetSession({});

console.log(widgetSession.plaid) // {}

const subscription = new Subscription({ plaid: widgetSession.plaid });

console.log(subscription.plaid) // MongooseDocument { undefined }

const charge = new Charge({});

charge.set({
  plaid: subscription.plaid
});

Im getting an error:

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at model.$set (node_modules/mongoose/lib/document.js:867:21)
    at model._handleIndex (node_modules/mongoose/lib/document.js:915:12)
    at model.$set (node_modules/mongoose/lib/document.js:879:22)
    at Context.<anonymous> (tests/unittests/models/subscription.spec.js:152:14)
    at processImmediate (internal/timers.js:439:21)
    at process.topLevelDomainCallback (domain.js:130:23)

What is the expected behavior?
charge.set method does not end up in failure

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.

Node.js: 12.14.1
Mongoose: 5.8.11
MongoDB: 4.2.0

@vkarpov15 vkarpov15 added this to the 5.8.13 milestone Feb 13, 2020
@vkarpov15 vkarpov15 added the needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue label Feb 13, 2020
@aleksandr-gorokhov
Copy link
Author

aleksandr-gorokhov commented Feb 13, 2020

repro script

'use strict';

const mongoose = require('mongoose');

mongoose.connect('mongodb://localhost:27017/test', {useNewUrlParser: true, useUnifiedTopology: true})

const widgetSessionSchema = new mongoose.Schema({
    plaid: {
        nestedKey: String
    }
});
const subscriptionSchema = new mongoose.Schema({
    plaid: {
        nestedKey: String
    }
});
const chargeSchema = new mongoose.Schema({
    plaid: {
        nestedKey: String
    }
});

const WidgetSession = mongoose.model('WidgetSession', widgetSessionSchema);
const Subscription = mongoose.model('Subscription', subscriptionSchema);
const Charge = mongoose.model('Charge', chargeSchema);

const widgetSession = new WidgetSession({});

console.log(widgetSession.plaid); // {}

const subscription = new Subscription({ plaid: widgetSession.plaid });

console.log(subscription.plaid); // MongooseDocument { undefined }

const charge = new Charge({});

charge.set({
    plaid: subscription.plaid
});

@vkarpov15 vkarpov15 modified the milestones: 5.9.1, 5.9.2 Feb 14, 2020
@vkarpov15 vkarpov15 added has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue and removed needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue labels Feb 19, 2020
vkarpov15 added a commit that referenced this issue Feb 20, 2020
vkarpov15 added a commit that referenced this issue Feb 20, 2020
@vkarpov15 vkarpov15 added confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue labels Feb 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

2 participants