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

fix infinite loop for mongoose #173

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

anhoev
Copy link

@anhoev anhoev commented May 19, 2018

Hi , i tried the tungus from root core , but if i use the findOneAndUpdate with Array , i will get error:
Example :

const gameSchema = Schema({
    name: String
    , developer: String
    , released: Date
    , consoles: {
        type: [{
            name: String,
        }]
    }
});
const Game = mongoose.model('Game', gameSchema);
async function example() {
    try {
        await Game.create({
            name: 'Legend of Zelda: Ocarina of Time',
            developer: 'Nintendo',
            released: new Date('November 21, 1998')
        });
        await Game.findOneAndUpdate({name: 'Legend of Zelda: Ocarina of Time'}, {$set: {consoles: [{name: '1'}, {name: '1'}]}});
    } catch (e) {
        console.warn(e);
    }
}
example();

RangeError: Maximum call stack size exceeded
at Object (native)
at /Users/anhtran/IdeaProjects/tungus2/node_modules/lodash/lodash.js:1190:19
at baseKeys (/Users/anhtran/IdeaProjects/tungus2/node_modules/lodash/lodash.js:3496:16)
at keys (/Users/anhtran/IdeaProjects/tungus2/node_modules/lodash/lodash.js:13298:60)
at /Users/anhtran/IdeaProjects/tungus2/node_modules/lodash/lodash.js:4912:21
at baseForOwn (/Users/anhtran/IdeaProjects/tungus2/node_modules/lodash/lodash.js:3002:24)
at /Users/anhtran/IdeaProjects/tungus2/node_modules/lodash/lodash.js:4886:18
at Function.forEach (/Users/anhtran/IdeaProjects/tungus2/node_modules/lodash/lodash.js:9334:14)
at tcoll._wrapTypes (/Users/anhtran/IdeaProjects/tungus2/node_modules/tingodb/lib/tcoll.js:419:4)
at /Users/anhtran/IdeaProjects/tungus2/node_modules/tingodb/lib/tcoll.js:427:9
at arrayEach (/Users/anhtran/IdeaProjects/tungus2/node_modules/lodash/lodash.js:508:11)
at Function.forEach (/Users/anhtran/IdeaProjects/tungus2/node_modules/lodash/lodash.js:9334:14)
at tcoll._wrapTypes (/Users/anhtran/IdeaProjects/tungus2/node_modules/tingodb/lib/tcoll.js:419:4)
at /Users/anhtran/IdeaProjects/tungus2/node_modules/tingodb/lib/tcoll.js:427:9
at /Users/anhtran/IdeaProjects/tungus2/node_modules/lodash/lodash.js:4917:15
at baseForOwn (/Users/anhtran/IdeaProjects/tungus2/node_modules/lodash/lodash.js:3002:24)

Mongoose send a obj with __parentArray to findAndModify and wrap function come into a infinite loop.
Maybe there are some cleaner method to fix this error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant