我正在尝试从破坏NodeJS 8.10的AWS Lambda函数连接到MongoDB数据库。 MongoDB副本集部署在自定义VPC内的3个EC2实例(1个主节点,1个辅助节点和1个仲裁器)上。我能够从运行Web服务器的单独EC2实例连接到mongodb副本集。我在Lambda中遇到的错误是
{ MongoError: seed list contains no mongos proxies, replicaset connections requires the parameter replicaSet to be supplied in the URI or options object,
mongodb://server:port/db?replicaSet=name
at connectCallback
(/var/task/node_modules/mongodb/lib/operations/mongo_client_ops.js:236:23)
at process.nextTick
(/var/task/node_modules/mongodb/lib/operations/mongo_client_ops.js:436:7)
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickDomainCallback (internal/process/next_tick.js:218:9)
name: 'MongoError',
message: 'seed list contains no mongos proxies, replicaset connections requires the parameter replicaSet to be supplied in the URI or options object, mongodb://server:port/db?replicaSet=name',
[Symbol(mongoErrorContextSymbol)]: {} }
我用来连接的代码是
'use strict';
const MongoClient = require('mongodb').MongoClient;
MongoClient.connect(mongo_uri, { useNewUrlParser: true }, function(err, client) {
callback(err, client);
});
mongo_uri 的格式为
mongodb:// uname:password @ ec2-dns-primary:27017,ec2-dns-secondary:27017 / dbname?replicaSet = replSetName&readPreference = primary
环境详细信息为:
Node: v8.10
MongoDB node module: 3.1.0
Lambda函数部署在部署了运行MongoDB的实例的同一VPC中。安全小组对我来说还可以。
关于如何使其工作或是否必须使用另一种语言(如python)的想法吗?