You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
methods defined on the Object/Array prototype throws error when mongoose.populate() is used #9876
Do you want to request a feature or report a bug?
bug What is the current behavior?
So I have a library in my project that defines a method on the prototype of Array and Object in node.js environment.
All mongoose api works fine, util I call populate() on them, then it throws an error like this:
C:\......\node_modules\mongodb\lib\cmap\connection.js:268
callback(new MongoError(document));
^
MongoError: BSON field 'OperationSessionInfo.lsid.reach' is an unknown field.
at MessageStream.messageHandler (C:\....\node_modules\mongodb\lib\cmap\connection.js:268:20)
at MessageStream.emit (node:events:379:20)
at processIncomingData (C:\....\node_modules\mongodb\lib\cmap\message_stream.js:144:12)
at MessageStream._write (C:\.....\node_modules\mongodb\lib\cmap\message_stream.js:42:5)
at writeOrBuffer (node:internal/streams/writable:400:12)
at _write (node:internal/streams/writable:341:10)
at MessageStream.Writable.write (node:internal/streams/writable:345:10)
at Socket.ondata (node:internal/streams/readable:750:22)
at Socket.emit (node:events:379:20)
at addChunk (node:internal/streams/readable:313:12)
at readableAddChunk (node:internal/streams/readable:288:9)
at Socket.Readable.push (node:internal/streams/readable:227:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
ok: 0,
code: 40415,
codeName: 'Location40415',
reach: undefined
}
in above example the method defined on prototype is called "reach", thus you see: "OperationSessionInfo.lsid.reach"
If the current behavior is a bug, please provide the steps to reproduce.
Just define a method on the prototype of Object and Array in node, and then try to run a query like this: SomeCollection.find({id: "some id"}).populate("some_field")
What is the expected behavior?
It should not throw error. Defining a method on the prototypes of Javascript is a valid action and should not conflict with mongoose methods. What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node: 15.7
mongoose: 5.11.14
Yes you are right, It is methods defined on the Object prototype,
I had the same bug in Node.js and I reported it and it was fixed in Node version 15.5
Activity
IslandRhythms commentedon Feb 1, 2021
Array doesn't create a problem but Object does.
seven-deuce commentedon Feb 2, 2021
Yes you are right, It is methods defined on the Object prototype,
I had the same bug in Node.js and I reported it and it was fixed in Node version 15.5
IslandRhythms commentedon Feb 2, 2021
If they said they fixed it then they reintroduced the same bug in 15.7
seven-deuce commentedon Feb 3, 2021
Nope, it is fixed, I am using 15.7
here is the thread related to that fix in node.js:
nodejs/node#36410
IslandRhythms commentedon Feb 3, 2021
We will be looking into this. Thank you for the report.
fix(utils): make clone() only copy own properties