leonardodalcin / mongo-auto-erd

Generates a .png ERD of a mongo database through a CLI
MIT License
20 stars 4 forks source link

Connecting to databaseMongoError: CMD_NOT_ALLOWED: mapReduce #19

Open kasir-barati opened 3 years ago

kasir-barati commented 3 years ago

What id did

  1. npm i -D mongo-auto-erd
  2. Add this scripts in the package.json file: "erd": "mongo-erd --db dbname --outfile ./erd --uri mongodb+srv://user:pass@atlas.mongo.net/dbname?authSource=admin&replicaSetatlas-xyz&readPreference=primary&ssl=true"

error message

\ Connecting to databaseMongoError: CMD_NOT_ALLOWED: mapReduce
    at MessageStream.messageHandler (/home/kasir/Salam-Sakhteman/infiniti-platform-server/node_modules/mongodb/lib/cmap/connection.js:272:20)
    at MessageStream.emit (events.js:400:28)
    at processIncomingData (/home/kasir/Salam-Sakhteman/infiniti-platform-server/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
    at MessageStream._write (/home/kasir/Salam-Sakhteman/infiniti-platform-server/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
    at writeOrBuffer (internal/streams/writable.js:358:12)
    at MessageStream.Writable.write (internal/streams/writable.js:303:10)
    at TLSSocket.ondata (internal/streams/readable.js:726:22)
    at TLSSocket.emit (events.js:400:28)
    at addChunk (internal/streams/readable.js:290:12)
    at readableAddChunk (internal/streams/readable.js:265:9)
    at TLSSocket.Readable.push (internal/streams/readable.js:204:10)
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:188:23) {
  ok: 0,
  code: 8000,
  codeName: 'AtlasError'
}

Database is on atlas Node version: 14.17.4 OS: ubuntu 20.04

Do you have any idea?

leonardodalcin commented 2 years ago

Whats your mongo version?

I suspect the error is caused by: https://github.com/leonardodalcin/mongo-auto-erd/blob/master/source/mongo/mapReduceCollectionProperties.ts#L12.

Probably the mapReduce method is not supported anymore.

fengxia41103 commented 1 year ago

Run into the same error. The same uri string worked w/ mongo cli client & mongo-express. So I'm sure the authentication worked actually. The user is an admin and have full previlige over this database. Thus I suspect it's the same error as mentioned above due ot mapReduce.

Mongo: 6.0.1 bitnami docker image

- Connecting to databaseMongoError: not authorized on test_database to execute command { mapReduce: "system.profile", map: "function () {
        // @ts-ignore
        // tslint:disable-next-line
        for (let key in this) {
            // @ts-ignore
            emit(key...", reduce: "function (key, values) {
        let result = [];
        if (Array.isArray(values)) {
            result = values;
        }
        else {
         ...", out: { inline: 1 }, limit: 50, lsid: { id: UUID("5f663ef8-9ddf-442e-9552-0798c9549a53") }, $db: "test_database" }
    at MessageStream.messageHandler (/home/fengxia/.npm/_npx/a3e7fde68de1b4c3/node_modules/mongodb/lib/cmap/connection.js:299:20)
    at MessageStream.emit (events.js:400:28)
    at processIncomingData (/home/fengxia/.npm/_npx/a3e7fde68de1b4c3/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
    at MessageStream._write (/home/fengxia/.npm/_npx/a3e7fde68de1b4c3/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
    at writeOrBuffer (internal/streams/writable.js:358:12)
    at MessageStream.Writable.write (internal/streams/writable.js:303:10)
    at Socket.ondata (internal/streams/readable.js:731:22)
    at Socket.emit (events.js:400:28)
    at addChunk (internal/streams/readable.js:293:12)
    at readableAddChunk (internal/streams/readable.js:267:9)
    at Socket.Readable.push (internal/streams/readable.js:206:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23) {
  ok: 0,
  code: 13,
  codeName: 'Unauthorized'
}