Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { MongoClient } from 'mongodb';
- const uri =
- 'mongodb://my:my@localhost:27017,localhost:27018,localhost:27019/my?replicaSet=rs0';
- try {
- const client = new MongoClient(uri);
- await client.connect();
- console.log('Connected to MongoDB Replica Set!');
- const db = client.db('my');
- const collection = db.collection('testcollection');
- const result = await collection.insertOne({
- message: 'Hello, MongoDB Replica Set!',
- });
- console.log('Inserted Document:', result.insertedId);
- await client.close();
- } catch (error) {
- console.error('Error connecting to MongoDB:', error);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement