Skip to content
This repository has been archived by the owner on Jul 1, 2020. It is now read-only.

Commit

Permalink
fix: ensureIndex DeprecationWarning
Browse files Browse the repository at this point in the history
  • Loading branch information
cklanac committed Oct 29, 2018
1 parent 0c6689d commit c88baac
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion scratch/queries.js
Expand Up @@ -5,7 +5,7 @@ const { MONGODB_URI } = require('../config');

const Note = require('../models/note');

mongoose.connect(MONGODB_URI)
mongoose.connect(MONGODB_URI, { useNewUrlParser: true, useCreateIndex : true })
.then(() => {

/**
Expand Down
3 changes: 1 addition & 2 deletions server.js
Expand Up @@ -43,14 +43,13 @@ app.use((err, req, res, next) => {
res.status(err.status).json(errBody);
} else {
res.status(500).json({ message: 'Internal Server Error' });
console.log(err.name === 'FakeError' ? '' : err);
}
});

// Listen for incoming connections
if (require.main === module) {
// Connect to DB and Listen for incoming connections
mongoose.connect(MONGODB_URI)
mongoose.connect(MONGODB_URI, { useNewUrlParser: true, useCreateIndex : true })
.then(instance => {
const conn = instance.connections[0];
console.info(`Connected to: mongodb://${conn.host}:${conn.port}/${conn.name}`);
Expand Down
10 changes: 5 additions & 5 deletions test/folders.test.js
Expand Up @@ -19,7 +19,7 @@ const sandbox = sinon.createSandbox();
describe('Noteful API - Folders', function () {

before(function () {
return mongoose.connect(TEST_MONGODB_URI, { useNewUrlParser: true })
return mongoose.connect(TEST_MONGODB_URI, { useNewUrlParser: true, useCreateIndex : true })
.then(() => Promise.all([
Note.deleteMany(),
Folder.deleteMany()
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('Noteful API - Folders', function () {
});

it('should catch errors and respond properly', function () {
sandbox.stub(Folder.schema.options.toObject, 'transform').throws('FakeError');
sandbox.stub(Folder.schema.options.toJSON, 'transform').throws('FakeError');
return chai.request(app).get('/api/folders')
.then(res => {
expect(res).to.have.status(500);
Expand Down Expand Up @@ -134,7 +134,7 @@ describe('Noteful API - Folders', function () {
});

it('should catch errors and respond properly', function () {
sandbox.stub(Folder.schema.options.toObject, 'transform').throws('FakeError');
sandbox.stub(Folder.schema.options.toJSON, 'transform').throws('FakeError');

let data;
return Folder.findOne()
Expand Down Expand Up @@ -218,7 +218,7 @@ describe('Noteful API - Folders', function () {
});

it('should catch errors and respond properly', function () {
sandbox.stub(Folder.schema.options.toObject, 'transform').throws('FakeError');
sandbox.stub(Folder.schema.options.toJSON, 'transform').throws('FakeError');

const newItem = { name: 'newFolder' };
return chai.request(app)
Expand Down Expand Up @@ -331,7 +331,7 @@ describe('Noteful API - Folders', function () {
});

it('should catch errors and respond properly', function () {
sandbox.stub(Folder.schema.options.toObject, 'transform').throws('FakeError');
sandbox.stub(Folder.schema.options.toJSON, 'transform').throws('FakeError');

const updateItem = { name: 'Updated Name' };
let data;
Expand Down
10 changes: 5 additions & 5 deletions test/notes.test.js
Expand Up @@ -20,7 +20,7 @@ const sandbox = sinon.createSandbox();
describe('Noteful API - Notes', function () {

before(function () {
return mongoose.connect(TEST_MONGODB_URI, { useNewUrlParser: true })
return mongoose.connect(TEST_MONGODB_URI, { useNewUrlParser: true, useCreateIndex : true })
.then(() => Promise.all([
Note.deleteMany(),
Folder.deleteMany(),
Expand Down Expand Up @@ -195,7 +195,7 @@ describe('Noteful API - Notes', function () {
});

it('should catch errors and respond properly', function () {
sandbox.stub(Note.schema.options.toObject, 'transform').throws('FakeError');
sandbox.stub(Note.schema.options.toJSON, 'transform').throws('FakeError');

return chai.request(app).get('/api/notes')
.then(res => {
Expand Down Expand Up @@ -250,7 +250,7 @@ describe('Noteful API - Notes', function () {
});

it('should catch errors and respond properly', function () {
sandbox.stub(Note.schema.options.toObject, 'transform').throws('FakeError');
sandbox.stub(Note.schema.options.toJSON, 'transform').throws('FakeError');
return Note.findOne()
.then(data => {
return chai.request(app).get(`/api/notes/${data.id}`);
Expand Down Expand Up @@ -410,7 +410,7 @@ describe('Noteful API - Notes', function () {
});

it('should catch errors and respond properly', function () {
sandbox.stub(Note.schema.options.toObject, 'transform').throws('FakeError');
sandbox.stub(Note.schema.options.toJSON, 'transform').throws('FakeError');

const newItem = {
title: 'The best article about cats ever!',
Expand Down Expand Up @@ -658,7 +658,7 @@ describe('Noteful API - Notes', function () {
});

it('should catch errors and respond properly', function () {
sandbox.stub(Note.schema.options.toObject, 'transform').throws('FakeError');
sandbox.stub(Note.schema.options.toJSON, 'transform').throws('FakeError');

const updateItem = {
title: 'What about dogs?!',
Expand Down
10 changes: 5 additions & 5 deletions test/tags.test.js
Expand Up @@ -19,7 +19,7 @@ const sandbox = sinon.createSandbox();
describe('Noteful API - Tags', function () {

before(function () {
return mongoose.connect(TEST_MONGODB_URI, { useNewUrlParser: true })
return mongoose.connect(TEST_MONGODB_URI, { useNewUrlParser: true, useCreateIndex : true })
.then(() => Promise.all([
Note.deleteMany(),
Tag.deleteMany()
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('Noteful API - Tags', function () {
});

it('should catch errors and respond properly', function () {
sandbox.stub(Tag.schema.options.toObject, 'transform').throws('FakeError');
sandbox.stub(Tag.schema.options.toJSON, 'transform').throws('FakeError');

return chai.request(app).get('/api/tags')
.then(res => {
Expand Down Expand Up @@ -136,7 +136,7 @@ describe('Noteful API - Tags', function () {
});

it('should catch errors and respond properly', function () {
sandbox.stub(Tag.schema.options.toObject, 'transform').throws('FakeError');
sandbox.stub(Tag.schema.options.toJSON, 'transform').throws('FakeError');

return Tag.findOne()
.then(data => {
Expand Down Expand Up @@ -220,7 +220,7 @@ describe('Noteful API - Tags', function () {
});

it('should catch errors and respond properly', function () {
sandbox.stub(Tag.schema.options.toObject, 'transform').throws('FakeError');
sandbox.stub(Tag.schema.options.toJSON, 'transform').throws('FakeError');

const newItem = { name: 'newTag' };
return chai.request(app)
Expand Down Expand Up @@ -337,7 +337,7 @@ describe('Noteful API - Tags', function () {
});

it('should catch errors and respond properly', function () {
sandbox.stub(Tag.schema.options.toObject, 'transform').throws('FakeError');
sandbox.stub(Tag.schema.options.toJSON, 'transform').throws('FakeError');

const updateItem = { name: 'Updated Name' };
return Tag.findOne()
Expand Down
8 changes: 4 additions & 4 deletions utils/seed-database.js
Expand Up @@ -11,17 +11,17 @@ const Tag = require('../models/tag');
const { folders, notes, tags } = require('../db/data');

console.log(`Connecting to mongodb at ${MONGODB_URI}`);
mongoose.connect(MONGODB_URI, { useNewUrlParser: true })
mongoose.connect(MONGODB_URI, { useNewUrlParser: true, useCreateIndex : true })
.then(() => {
console.info('Delete Data');
console.info('Deleting Data...');
return Promise.all([
Note.deleteMany(),
Folder.deleteMany(),
Tag.deleteMany(),
]);
})
.then(() => {
console.info('Seeding Database');
console.info('Seeding Database...');
return Promise.all([
Note.insertMany(notes),
Folder.insertMany(folders),
Expand All @@ -30,7 +30,7 @@ mongoose.connect(MONGODB_URI, { useNewUrlParser: true })
})
.then(results => {
console.log('Inserted', results);
console.info('Disconnecting');
console.info('Disconnecting...');
return mongoose.disconnect();
})
.catch(err => {
Expand Down

0 comments on commit c88baac

Please sign in to comment.