Skip to content

Instantly share code, notes, and snippets.

@lineus lineus/mongooseSrvTest.js Secret
Created Aug 17, 2018

Embed
What would you like to do?
fails with mongoose
#!/usr/bin/env node
'use strict';
const env = require('/Users/lineus/.env');
const uri = env.ATLASSRV_HOST_ONLY;
const sharable = uri.replace(/cl[^:]+mon/, 'cluster.mon');
const opts = {
dbName: 'forSnehanshu',
user: env.ATLAS_USER,
pass: env.ATLAS_PASS,
useNewUrlParser: true
};
const mongoose = require('mongoose');
mongoose.connect(uri, opts);
const conn = mongoose.connection;
const Schema = mongoose.Schema;
const schema = new Schema({
name: String
});
const Test = mongoose.model('test', schema);
const test1 = new Test({ name: 'one' });
const test2 = new Test({ name: 'two' });
async function run() {
console.log(`version: ${mongoose.version}`);
console.log(`conn string: ${sharable}`);
await conn.dropDatabase().catch(error);
await Test.create([test1, test2]).catch(error);
let docs = await Test.find().catch(error);
console.log(docs);
return conn.close().catch(error);
}
run();
function error(e) {
console.error(e.message);
}
issues: ./mongooseSrvTest.js
version: 5.2.9
conn string: mongodb+srv://cluster.mongodb.net/?retryWrites=true
user is not allowed to do action [dropDatabase] on [forSnehanshu.]
user is not allowed to do action [insert] on [forSnehanshu.tests]
(node:16342) DeprecationWarning: collection.find option [fields] is deprecated and will be removed in a later version.
user is not allowed to do action [find] on [forSnehanshu.tests]
undefined
issues:
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.