-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Model.findOneAndUpdate() has infinite loop when there's Map in the dbref's schema #6750
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Comments
Below script executes without error on mongoose 5.2.4, can you modify the below script to repro your issue? const assert = require('assert');
const mongoose = require('mongoose');
mongoose.set('debug', true);
const GITHUB_ISSUE = `gh6750`;
const connectionString = `mongodb://localhost:27017/${ GITHUB_ISSUE }`;
const { Schema } = mongoose;
run().then(() => console.log('done')).catch(error => console.error(error.stack));
async function run() {
await mongoose.connect(connectionString);
await mongoose.connection.dropDatabase();
const User = mongoose.model('User', {
maps: { type: Map, of: String },
});
const Post = mongoose.model('Post', {
user: { type: Schema.Types.ObjectId, ref: 'User' },
});
const user = await User.create({});
const doc = await Post.findOneAndUpdate({user}, {user}, {upsert: true, new: true});
console.log('Doc', doc);
} |
vkarpov15
added
the
can't reproduce
Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity.
label
Jul 22, 2018
Construct the map with a default '{}', then it can trigger error like
const assert = require('assert');
const mongoose = require('mongoose');
mongoose.set('debug', true);
const GITHUB_ISSUE = `gh6750`;
const connectionString = `mongodb://localhost:27017/${ GITHUB_ISSUE }`;
const { Schema } = mongoose;
run().then(() => console.log('done')).catch(error => console.error(error.stack));
async function run() {
await mongoose.connect(connectionString);
await mongoose.connection.dropDatabase();
const User = mongoose.model('User', {
maps: { type: Map, of: String, default: {} },
});
const Post = mongoose.model('Post', {
user: { type: Schema.Types.ObjectId, ref: 'User' },
});
const user = await User.create({});
const doc = await Post.findOneAndUpdate({user}, {user}, {upsert: true, new: true});
console.log('Doc', doc);
} |
vkarpov15
added
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
and removed
can't reproduce
Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity.
labels
Jul 25, 2018
Thanks for reporting, will fix asap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you want to request a feature or report a bug?
It's a bug.
What is the current behavior?
Model.findOneAndUpdate() hangs when update has a reference model which has a Map as a field.
If the current behavior is a bug, please provide the steps to reproduce.
I took a quick investigation. In lib/helpers/common.js function modifiedPaths will recursive call itself when there's map, because there is a key $__parent generated when model has a Map.
What is the expected behavior?
No infinite loop.
Please mention your node.js, mongoose and MongoDB version.
node v10.5.0
mongoose 5.2.4
mongodb v3.6.4
The text was updated successfully, but these errors were encountered: