Skip to content

Instantly share code, notes, and snippets.

@lineus lineus/output.txt Secret
Created Aug 17, 2018

What would you like to do?
using native driver with srv and options in object
$: ./srvUriNoCreds.js
version: 3.1.3
conn string: mongodb+srv://
{ _id: 5b7718923eace33f25684a05, name: 'Billy' }
#!/usr/bin/env node --no-deprecation
'use strict';
const env = require('/Users/lineus/.env');
const { MongoClient } = require('mongodb');
const uri = env.ATLASSRV_HOST_ONLY;
const opts = { auth: { user: env.ATLAS_USER, password: env.ATLAS_PASS } };
const sharable = uri.replace( /cl[^:]+mon/, 'cluster.mon');
const pkg = require.resolve('mongodb').replace(/\/[^/]*$/, '/package.json');
const ver = require(pkg).version;
async function run() {
console.log(`version: ${ver}`);
console.log(`conn string: ${sharable}`);
const client = await MongoClient.connect(uri, opts);
const db = client.db('gh-6667');
await db.dropDatabase().catch(handleError);
await db
.insert({ name: 'Billy' })
let found = await db
function handleError(e) {
return console.error(e.message);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.