0

我正在尝试与 node.js 和 mongodb 一起学习 docker 概念。我在 docker 容器中运行了一个 node js 应用程序。它唯一的作用是在 mongo db 数据库中更新/更新文档。我使用的这个 mongodb 数据库托管在 Mongodb Atlas 上。node index.js当我直接在命令行中运行 node.js时,它可以正常工作。文档得到更新。但是,如果我将 docker 容器运行为

docker run firstdatabase:latest

它不更新数据库。但是,我确实从数据库中得到了以下响应:

    D:\nodes\firstDatabase>docker run -it firstdatabase:latest 
database created CommandResult {   result:    { n: 1,
         nModified: 0,
         opTime: { ts: [Object], t: 2 },
         electionId: 7fffffff0000000000000002,
         ok: 1 },   connection:    Connection {
         domain: null,
         _events:
          { error: [Object],
            close: [Object],
            timeout: [Object],
            parseError: [Object] },
         _eventsCount: 4,
         _maxListeners: undefined,
         options:
          { host: 'cluster0-shard-00-01-7srki.mongodb.net',
            port: 27017,
            size: 5,
            minSize: 0,
            connectionTimeout: 30000,
            socketTimeout: 360000,
            keepAlive: true,
            keepAliveInitialDelay: 300000,
            noDelay: true,
            ssl: true,
            checkServerIdentity: true,
            ca: null,
            crl: null,
            cert: null,
            key: null,
            passPhrase: null,
            rejectUnauthorized: false,
            promoteLongs: true,
            promoteValues: true,
            promoteBuffers: false,
            reconnect: false,
            reconnectInterval: 1000,
            reconnectTries: 30,
            domainsEnabled: false,
            disconnectHandler: [Object],
            cursorFactory: [Object],
            emitError: true,
            socketOptions: {},
            setName: 'Cluster0-shard-0',
            promiseLibrary: [Function: Promise],
            clientInfo: [Object],
            authProviders: [Object],
            monitoring: false,
            parent: [Object],
            user: 'xyz',
            password: '****',
            read_preference_tags: null,
            authSource: 'admin',
            readPreference: [Object],
            rs_name: 'Cluster0-shard-0',
            dbName: 'admin',
            servers: [Array],
            auth: [Object],
            server_options: [Object],
            db_options: [Object],
            rs_options: [Object],
            mongos_options: [Object],
            socketTimeoutMS: 360000,
            connectTimeoutMS: 30000,
            bson: BSON {} },
         id: 2,
         logger: Logger { className: 'Connection' },
         bson: BSON {},
         tag: undefined,
         messageHandler: [Function],
         maxBsonMessageSize: 67108864,
         port: 27017,
         host: 'cluster0-shard-00-01-7srki.mongodb.net',
         family: undefined,
         keepAlive: true,
         keepAliveInitialDelay: 300000,
         noDelay: true,
         connectionTimeout: 30000,
         socketTimeout: 360000,
         destroyed: false,
         domainSocket: false,
         singleBufferSerializtion: true,
         serializationFunction: 'toBinUnified',
         ca: null,
         crl: null,
         cert: null,
         key: null,
         passphrase: null,
         ciphers: null,
         ecdhCurve: null,
         ssl: true,
         rejectUnauthorized: false,
         checkServerIdentity: true,
         responseOptions:
          { promoteLongs: true,
            promoteValues: true,
            promoteBuffers: false },
         flushing: false,
         queue: [],
         connection:
          TLSSocket {
            _tlsOptions: [Object],
            _secureEstablished: true,
            _securePending: false,
            _newSessionPending: false,
            _controlReleased: true,
            _SNICallback: null,
            servername: null,
            npnProtocol: undefined,
            alpnProtocol: false,
            authorized: true,
            authorizationError: null,
            encrypted: true,
            _events: [Object],
            _eventsCount: 8,
            connecting: false,
            _hadError: false,
            _handle: [Object],
            _parent: null,
            _host: 'cluster0-shard-00-01-7srki.mongodb.net',
            _readableState: [Object],
            readable: true,
            domain: null,
            _maxListeners: undefined,
            _writableState: [Object],
            writable: true,
            allowHalfOpen: false,
            _bytesDispatched: 981,
            _sockname: null,
            _pendingData: null,
            _pendingEncoding: '',
            server: undefined,
            _server: null,
            ssl: [Object],
            _requestCert: true,
            _rejectUnauthorized: false,
            _idleTimeout: 360000,
            _idleNext: [Object],
            _idlePrev: [Object],
            _idleStart: 4777,
            _destroyed: false,
            read: [Function],
            _consuming: true,
            [Symbol(asyncId)]: 27,
            [Symbol(bytesRead)]: 0,
            [Symbol(asyncId)]: 30,
            [Symbol(triggerAsyncId)]: 11 },
         writeStream: null,
         hashedName: '0de073ba71529deddc76bfe3d186c51c10aed56e',
         workItems: [],
         buffer: null,
         sizeOfMessage: 0,
         bytesRead: 0,
         stubBuffer: null },   message:    Response {
         parsed: true,
         raw: <Buffer 87 00 00 00 b6 40 81 06 0d 00 00 00 01 00 00 00 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 63 00 00 00 10 6e 00 01 00 00 00 10 6e 4d ... >,
         data: <Buffer 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 63 00 00 00 10 6e 00 01 00 00 00 10 6e 4d 6f 64 69 66 69 65 64 00 00 00 00 00 03 6f 70 54 ... >,
         bson: BSON {},
         opts:
          { promoteLongs: true,
            promoteValues: true,
            promoteBuffers: false },
         length: 135,
         requestId: 109134006,
         responseTo: 13,
         opCode: 1,
         fromCompressed: undefined,
         responseFlags: 8,
         cursorId: Long { _bsontype: 'Long', low_: 0, high_: 0 },
         startingFrom: 0,
         numberReturned: 1,
         documents: [ [Object] ],
         cursorNotFound: false,
         queryFailure: false,
         shardConfigStale: false,
         awaitCapable: true,
         promoteLongs: true,
         promoteValues: true,
         promoteBuffers: false,
         index: 119,
         hashedName: '0de073ba71529deddc76bfe3d186c51c10aed56e' },   modifiedCount: 0,   upsertedId: null,   upsertedCount: 0,   matchedCount: 1 }

可能是什么原因?

4

0 回答 0