我已经通过蒙戈阿特拉斯创建了M0集群沙箱。它运行得很好。但我想用它进行交易。我读过,为了使用事务,我需要一个副本集。
在阿特拉斯中,我的数据库似乎已经有了一个replicaSet (我什么都没做)。那我怎么能连接到那个复制集呢?

我现在的连接链接是mongodb+srv://admin:password@de.xxx.mongodb.net/db?retryWrites=true&w=majority
提前感谢!
发布于 2022-03-12 09:22:35
在创建MongoClient对象时传递连接字符串就足够了:
const { MongoClient, ServerApiVersion } = require('mongodb');
const uri = "your_string_connection";
const client = new MongoClient(uri, { options-you-need });
client.connect(err => {
const collection = client.db("test").collection("devices");
// perform actions on the collection object
client.close();
});此代码是从地图集中复制粘贴的,用于连接到集群:连接应用程序、->、check、Include full driver code example。
https://stackoverflow.com/questions/71448180
复制相似问题