Skip to content

methods defined on the Object/Array prototype throws error when mongoose.populate() is used #9876

@seven-deuce

Description

@seven-deuce

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

Metadata

Metadata

Assignees

Labels

confirmed-bugWe've confirmed this is a bug in Mongoose and will fix it.interop issueissue with interop between Mongoose and another npm module that is not a Mongoose prod dependency

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions