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

unexpected warning : To create a new ObjectId please try Mongoose.Types.ObjectId instead of using Mongoose.Schema.ObjectId. #5587

Closed
DariosDjimado opened this issue Aug 27, 2017 · 1 comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@DariosDjimado
Copy link

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

What is the current behavior?
The warning is shown even if we're not creating a new ObjectId

If the current behavior is a bug, please provide the steps to reproduce.

var mongoose = require('mongoose');

var zoneSchema = new mongoose.Schema({
    employees: {
        certifications: {type: mongoose.Schema.Types.ObjectId, ref: 'Certifications'}
    }
});

var certificationsSchema = new mongoose.Schema({
    type: String,
    list: [{type: mongoose.Schema.Types.ObjectId, ref: 'Certification'}]
});

var certificationSchema = new mongoose.Schema({
    name: String
});

var Zone = mongoose.model('Zone', zoneSchema);
var Certifications = mongoose.model('Certifications', certificationsSchema);
var Certification = mongoose.model('Certification', certificationSchema);

var newZone = new Zone();

What is the expected behavior?
Do not show the warning when it is not an explicit instance of new ObjectId

Please mention your node.js, mongoose and MongoDB version.
Node v8.2.1
Mongoose v4.11.8
MongoDB v3.2.7

@vkarpov15 vkarpov15 added this to the 4.11.10 milestone Aug 31, 2017
@vkarpov15 vkarpov15 added the bug? label Aug 31, 2017
@vkarpov15
Copy link
Collaborator

Sorry about the snafu, we'll release a fix later this week. This was an unintentional side effect of #5571 because 'employees.certifications' happens to be exactly 24 characters long. This issue should go away unless you happen to have a top-level property that's a 24 character hex string, and we now have an option to suppress the warning for that (hopefully) unusual edge case.

@vkarpov15 vkarpov15 added confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed bug? labels Aug 31, 2017
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