错误:MongoServerSelectionError:连接ECONNREFUSED 127.0.0.1:27020

问题描述 投票:0回答:1

我正在尝试使用 MongoDB 客户端字段级加密,使用他们的代码示例,但不断收到此错误:

MongoServerSelectionError:连接ECONNREFUSED 127.0.0.1:27020

这是我正在使用的代码:

const clientEncryption = new ClientEncryption(unencryptedClient, {
      kmsProviders,
      keyVaultNamespace,
    });

// genrate encyption key
const dataKeyId = await clientEncryption.createDataKey("local").then(() =\> {
  console.log("Encyption key genrated");
});

const schemaMap = {
  \[\`${dbName}.${collName}\`\]: {
    properties: {
      sensitiveField: {
        encrypt: {
          keyId: \[dataKeyId\],
          bsonType: "string",
          algorithm: "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic",
        },
      },
    },
  },
};

const encryptedClient = new MongoClient(URL, {
  useUnifiedTopology: true,
  autoEncryption: {
    keyVaultNamespace,
    kmsProviders,
    schemaMap,
  },
});

try {
  await encryptedClient.connect();
  const db = encryptedClient.db(dbName);
  const collection = db.collection(collName);

  `const` doc = {
    medicalRecords: "my-sensitive-data",
    sensitiveField: "hsbdb-jd256b",
    bloodType: "O+",
    insurance: "hgvdw35w6-7643",
  };


  const result = await collection.insertOne(doc);
  // const result = await collection.findOne({ bloodType: "O+" });
  // console.log("result: ", result);
  if (result) console.log("data entered successfully");
} catch (error) {
  console.log("Error:", error);
}
javascript node.js mongodb mongodb-query mongodb-csfle
1个回答
1
投票

27020
是 mongocryptd 二进制文件的默认端口。请参阅 #2 here 中的描述。但是,我建议使用共享库而不是 mongocryptd。请参阅我的回答here,特别是关于
cryptSharedLibPath

的部分
© www.soinside.com 2019 - 2024. All rights reserved.