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

Bug: Mongoose ver. 5.11.X breaks population #9640

Closed
avichaishapira1 opened this issue Dec 3, 2020 · 3 comments
Closed

Bug: Mongoose ver. 5.11.X breaks population #9640

avichaishapira1 opened this issue Dec 3, 2020 · 3 comments
Milestone

Comments

@avichaishapira1
Copy link

avichaishapira1 commented Dec 3, 2020

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

a bug
What is the current behavior?
reproduction: basic model population:
query = mongoose.model('stories').find(conditionsInfo);
let populate = 'desk'
query.populate(populate);

{“error”:“Error: Can only use numbers in square bracket path notation, got character \“o\” in path \“desk[object\“\n at stringToParts (/usr/src/app/node_modules/mpath/lib/stringToParts.js:10:13)\n at Object.exports.get (/usr/src/app/node_modules/mpath/lib/index.js:51:7)\n at getModelsMapForPopulate (/usr/src/app/node_modules/mongoose/lib/helpers/populate/getModelsMapForPopulate.js:242:32)\n at populate (/usr/src/app/node_modules/mongoose/lib/model.js:4323:21)\n at _populate (/usr/src/app/node_modules/mongoose/lib/model.js:4293:5)\n at db.base._promiseOrCallback.cb (/usr/src/app/node_modules/mongoose/lib/model.js:4269:5)\n at promiseOrCallback (/usr/src/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:9:12)\n at Mongoose._promiseOrCallback (/usr/src/app/node_modules/mongoose/lib/index.js:1135:10)\n at Function.Model.populate (/usr/src/app/node_modules/mongoose/lib/model.js:4267:23)\n at model.Query.Query._completeOne (/usr/src/app/node_modules/mongoose/lib/query.js:2078:9)\n at Immediate.Query.base.findOne.call (/usr/src/app/node_modules/mongoose/lib/query.js:2117:10)\n at Immediate._onImmediate (/usr/src/app/node_modules/mquery/lib/utils.js:116:16)\n at runCallback (timers.js:810:20)\n at tryOnImmediate (timers.js:768:5)\n at processImmediate [as _immediateCallback] (timers.js:745:5)“}

looking at the mongoose.model object we observe this:

 _mongooseOptions: {
    populate: {
      'desk[object': [PopulateOptions],
      'Object],[object': [PopulateOptions],
      'Object]': [PopulateOptions]
    }
@vkarpov15 vkarpov15 added this to the 5.11.3 milestone Dec 3, 2020
@vkarpov15
Copy link
Collaborator

Can you show your schemas please? That will help us repro and fix this.

@vkarpov15 vkarpov15 added the needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity label Dec 3, 2020
@vkarpov15 vkarpov15 removed this from the 5.11.3 milestone Dec 3, 2020
@avichaishapira1
Copy link
Author

 let schema = {
            headline: {type: String, require: true},
            type: {type: String, require: true},
            createdAt: {type: Date, require: true, default: Date.now},
            lastUpdate: {type: Date, require: true, default: Date.now},
            _owner: {
                userId: {type: ObjectId, required: true, ref: 'users0.1'},
                deskId: {type: ObjectId, require: true, ref: 'desks'},
                organizationId: {type: ObjectId, require: true},
            },
            _parent: {
                storyId: {type: ObjectId, require: true},
                videoId: {type: ObjectId, require: true},
                groupId: {type: ObjectId, require: true},
            },
            _opt: {
                deleted: {type: Boolean},
                status: {type: String, require: true},
            },
            _admin: {
                isDefault: {type: Boolean},
                emailNotify: {type: String},
            },
        };

As you can see 'desk' is not actually part of the schema. However it didn't error before

@vkarpov15 vkarpov15 added needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue and removed needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity labels Dec 6, 2020
@vkarpov15 vkarpov15 modified the milestones: 5.11.5, 5.11.6, 5.11.7, 5.11.8 Dec 6, 2020
@vkarpov15 vkarpov15 modified the milestones: 5.11.8, 5.11.9, 5.11.10 Dec 14, 2020
vkarpov15 added a commit to mongoosejs/mpath that referenced this issue Dec 30, 2020
@vkarpov15
Copy link
Collaborator

I haven't been able to repro this issue, but I put in a patch to mpath in mongoosejs/mpath@ffed519 that should fix this issue. Now mpath will treat desk[object Object] as a property name rather than treating [object Object] as an attempt to index into an array. That should fix this issue 👍

@vkarpov15 vkarpov15 removed the needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue label Dec 30, 2020
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

No branches or pull requests

2 participants