Uploaded image for project: 'Help-Desk'
  1. Help-Desk
  2. HELP-22018

FIWARE.Question.Tech.Fiware IoT Agent JSON connection to MongoDB with authentication.

    Details

    • Type: Monitor
    • Status: Closed
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: FIWARE-TECH-HELP
    • Labels:

      Description

      Created question in FIWARE Q/A platform on 14-08-2023 at 21:08
      Please, ANSWER this question AT https://stackoverflow.com/questions/76902281/fiware-iot-agent-json-connection-to-mongodb-with-authentication

      Question:
      Fiware IoT Agent JSON connection to MongoDB with authentication

      Description:
      I'm trying to configure the Fiware IOT Agent Json connection to MongoDB with authentication, but I always get the Authentication Failed error.
      I'm running the services via docker-compose, and in the Fiware IOT Agent JSON I have the environment variables IOTA_MONGO_USER and IOTA_MONGO_PASSWORD defined, which correspond to the mongodb username and password.
      Here I put some parts of my docker-compose:
      iot-agent:
      image: fiware/iotagent-json:latest
      hostname: iot-agent
      container_name: fiware-iot-agent
      depends_on:

      • mongo-db
        networks:
      • fiware
        ports:
      • "4041:4041"
      • "7896:7896"
        environment:
      • IOTA_MONGO_HOST=mongo-db
      • IOTA_MONGO_PORT=$ {MONGO_DB_PORT}
        - IOTA_MONGO_USER=${MONGO_USER}
        - IOTA_MONGO_PASSWORD=${MONGO_PWD}
        - IOTA_MONGO_DB=iotagentul
        mongo-db:
        image: mongo:${MONGO_DB_VERSION}
        hostname: mongo-db
        container_name: db-mongo
        expose:
        - "${MONGO_DB_PORT}

        "
        ports:

      • "$ {MONGO_DB_PORT}:${MONGO_DB_PORT}

        " # localhost:27017
        networks:

      • fiware
        volumes:
      • ./volumes/mongo-db/db:/data/db
        environment:
      • MONGO_INITDB_ROOT_USERNAME=$ {MONGO_USER}
      • MONGO_INITDB_ROOT_PASSWORD=$ {MONGO_PWD}

      The error log is this:
      (Note: the user and password in the fields below appears fine, I removed it from the post for security)

      subsrv=n/a | msg=Attempting to connect to MongoDB instance with url "mongodb://mongo-db:27017/iotagentul" and options {"auth":{"user":"","password":""}}. Attempt 1 | comp=IoTAgent
      (node:1) [MONGODB DRIVER] Warning: 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.
      (Use node --trace-warnings ... to show where the warning was created)
      (node:1) [MONGODB DRIVER] Warning: Warning: no saslprep library specified. Passwords will not be sanitized

      time=2023-08-14T21:12:11.543Z | lvl=ERROR | corr=9ad5f04f-8b95-4292-837e-54c57de0461d | trans=9ad5f04f-8b95-4292-837e-54c57de0461d | op=IoTAgentNGSI.DbConn | from=n/a | srv=n/a | subsrv=n/a | msg=MONGODB-001: Error trying to connect to MongoDB: MongoNetworkError: failed to connect to server [mongo-db:27017] on first connect [MongoError: Authentication failed.
      at Connection.messageHandler (/opt/iotagent-json/node_modules/mongodb/lib/core/connection/connection.js:364:19)
      at Connection.emit (node:events:513:28)
      at Connection.emit (node:domain:552:15)
      at processMessage (/opt/iotagent-json/node_modules/mongodb/lib/core/connection/connection.js:456:10)
      at Socket. (/opt/iotagent-json/node_modules/mongodb/lib/core/connection/connection.js:625:15)
      at Socket.emit (node:events:513:28)
      at Socket.emit (node:domain:552:15)
      at addChunk (node:internal/streams/readable:315:12)
      at readableAddChunk (node:internal/streams/readable:289:9)
      at Socket.Readable.push (node:internal/streams/readable:228:10)
      at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
      at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
      ok: 0,
      code: 18,
      codeName: 'AuthenticationFailed'
      }]

      Does anyone know what could be going wrong?
      Thanks

        Activity

        Hide
        backlogmanager Backlog Manager added a comment -

        2023-08-15 05:31|CREATED monitor | # answers= 0, accepted answer= False

        Show
        backlogmanager Backlog Manager added a comment - 2023-08-15 05:31|CREATED monitor | # answers= 0, accepted answer= False
        Hide
        backlogmanager Backlog Manager added a comment -

        2023-10-12 05:31|UPDATED status: transition Answer| # answers= 1, accepted answer= False

        Show
        backlogmanager Backlog Manager added a comment - 2023-10-12 05:31|UPDATED status: transition Answer| # answers= 1, accepted answer= False
        Hide
        backlogmanager Backlog Manager added a comment -

        2023-10-13 05:31|UPDATED status: transition Finish| # answers= 1, accepted answer= True

        Show
        backlogmanager Backlog Manager added a comment - 2023-10-13 05:31|UPDATED status: transition Finish| # answers= 1, accepted answer= True

          People

          • Assignee:
            mapedraza Miguel Ángel Pedraza
            Reporter:
            backlogmanager Backlog Manager
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: