Automattic / mongoose

MongoDB object modeling designed to work in an asynchronous environment.
https://mongoosejs.com
MIT License
26.92k stars 3.84k forks source link

Node app crashed when mongo returns admin user not authorized error #9307

Closed taikulawo closed 4 years ago

taikulawo commented 4 years ago

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

bug

What is the current behavior?

cannot read map of undefined

node:67376) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
(node:67376) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.

/Users/wuweichao/codes/nodeconf/node_modules/mongodb/lib/operations/execute_operation.js:70
    callback(err, result);
    ^
TypeError: Cannot read property 'map' of undefined
    at /Users/wuweichao/codes/nodeconf/node_modules/mongoose/lib/model.js:3315:58
    at executeCallback (/Users/wuweichao/codes/nodeconf/node_modules/mongodb/lib/operations/execute_operation.js:70:5)
    at bulkWriteOperation.execute (/Users/wuweichao/codes/nodeconf/node_modules/mongodb/lib/operations/insert_many.js:42:23)
    at bulk.execute (/Users/wuweichao/codes/nodeconf/node_modules/mongodb/lib/operations/bulk_write.js:70:16)
    at err (/Users/wuweichao/codes/nodeconf/node_modules/mongodb/lib/utils.js:385:14)
    at executeCallback (/Users/wuweichao/codes/nodeconf/node_modules/mongodb/lib/utils.js:375:25)
    at handleCallback (/Users/wuweichao/codes/nodeconf/node_modules/mongodb/lib/utils.js:102:55)
    at resultHandler (/Users/wuweichao/codes/nodeconf/node_modules/mongodb/lib/bulk/common.js:503:14)
    at handler (/Users/wuweichao/codes/nodeconf/node_modules/mongodb/lib/core/topologies/mongos.js:916:14)
    at /Users/wuweichao/codes/nodeconf/node_modules/mongodb/lib/core/connection/pool.js:405:18
    at process._tickCallback (internal/process/next_tick.js:61:11)
Waiting for the debugger to disconnect...
Process exited with code 1

If the current behavior is a bug, please provide the steps to reproduce. I cannot give you a brief repo to reproduce. But I have some screenshot when debugging mongoose's codes with following stackoverflow question :(

https://stackoverflow.com/questions/23943651/mongodb-admin-user-not-authorized

The mongo database which I currently used is company based, so I can't provide it

image

The following condition is false, so there no writeErrors exists in error

error.writeErrors == null &&
            get(error, 'result.result.writeErrors') != null

which cause TypeError: Cannot read property 'map' of undefined finally and my nodejs app crashed.

// writeErrors is undefined
error.writeErrors.map(err => err.index)

What is the expected behavior?

I found that you commit file change. https://github.com/Automattic/mongoose/commit/b5c52117841edfe956656a4ed62d1d7b39d771ef

mongoose not authorized on admin to exec is not a mongo CRUD error, it's appear when I try to write to collection. I think it's a bug personally your don't figure on.

If it's expected behavior, it's must be my fault.

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.

node: v10.16.0
mongoose: "^5.9.27"
mongodb: {
db version v4.4.0
Build Info: {
    "version": "4.4.0",
    "gitVersion": "563487e100c4215e2dce98d0af2a6a5a2d67c5cf",
    "modules": [],
    "allocator": "system",
    "environment": {
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}
taikulawo commented 4 years ago

update

I have rollback mongoose v5.7.34, it seems works @vkarpov15 . Is that a bug 😅?

taikulawo commented 4 years ago

I guess I have forget input database name.. sorry