Skip to content

Commit

Permalink
chore: more deprecation cleanup re: #6880
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Aug 23, 2018
1 parent 2206195 commit 37a9d8a
Show file tree
Hide file tree
Showing 15 changed files with 162 additions and 184 deletions.
2 changes: 1 addition & 1 deletion lib/model.js
Expand Up @@ -1100,7 +1100,7 @@ Model.syncIndexes = function syncIndexes(options, callback) {
if (err != null) {
return cb(err);
}
this.ensureIndexes(options, err => {
this.createIndexes(options, err => {
if (err != null) {
return cb(err);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/query.js
Expand Up @@ -88,7 +88,7 @@ function Query(conditions, options, model, collection) {

// For gh-6880. mquery still needs to support `fields` by default for old
// versions of MongoDB
this.options.useProjection = true;
this.$useProjection = true;

const collation = get(this, 'schema.options.collation', null);
if (collation != null) {
Expand Down
7 changes: 7 additions & 0 deletions test/common.js
Expand Up @@ -15,6 +15,10 @@ if (process.env.D === '1') {
mongoose.set('debug', true);
}

// For 3.1.3 deprecations
mongoose.set('useFindAndModify', false);
mongoose.set('useCreateIndex', true);

/**
* Override all Collection related queries to keep count
*/
Expand Down Expand Up @@ -82,6 +86,9 @@ module.exports = function(options) {
var noErrorListener = !!options.noErrorListener;
delete options.noErrorListener;

// For 3.1.3 deprecations
options.useNewUrlParser = true;

var conn = mongoose.createConnection(uri, options);

if (noErrorListener) {
Expand Down
16 changes: 8 additions & 8 deletions test/docs/validation.test.js
Expand Up @@ -399,7 +399,7 @@ describe('validation docs', function() {
}, 'Invalid color');

var opts = { runValidators: true };
Toy.update({}, { color: 'bacon' }, opts, function (err) {
Toy.updateOne({}, { color: 'bacon' }, opts, function (err) {
assert.equal(err.errors.color.message,
'Invalid color');
// acquit:ignore:start
Expand Down Expand Up @@ -442,7 +442,7 @@ describe('validation docs', function() {
var update = { color: 'red', name: 'Red Power Ranger' };
var opts = { runValidators: true };

Toy.update({}, update, opts, function(error) {
Toy.updateOne({}, update, opts, function(error) {
// The update validator throws an error:
// "TypeError: Cannot read property 'toLowerCase' of undefined",
// because `this` is **not** the document being updated when using
Expand Down Expand Up @@ -481,7 +481,7 @@ describe('validation docs', function() {
// Note the context option
var opts = { runValidators: true, context: 'query' };

Toy.update({}, update, opts, function(error) {
Toy.updateOne({}, update, opts, function(error) {
assert.ok(error.errors['color']);
// acquit:ignore:start
done();
Expand Down Expand Up @@ -512,15 +512,15 @@ describe('validation docs', function() {

var update = { color: 'blue' };
var opts = { runValidators: true };
Kitten.update({}, update, opts, function(err) {
Kitten.updateOne({}, update, opts, function(err) {
// Operation succeeds despite the fact that 'name' is not specified
// acquit:ignore:start
--outstanding || done();
// acquit:ignore:end
});

var unset = { $unset: { name: 1 } };
Kitten.update({}, unset, opts, function(err) {
Kitten.updateOne({}, unset, opts, function(err) {
// Operation fails because 'name' is required
assert.ok(err);
assert.ok(err.errors['name']);
Expand Down Expand Up @@ -565,10 +565,10 @@ describe('validation docs', function() {

var update = { $inc: { number: 1 } };
var opts = { runValidators: true };
Test.update({}, update, opts, function(error) {
Test.updateOne({}, update, opts, function(error) {
// There will never be a validation error here
update = { $push: [{ message: 'hello' }, { message: 'world' }] };
Test.update({}, update, opts, function(error) {
Test.updateOne({}, update, opts, function(error) {
// This will never error either even though the array will have at
// least 2 elements.
// acquit:ignore:start
Expand Down Expand Up @@ -600,7 +600,7 @@ describe('validation docs', function() {
}
};
var opts = { runValidators: true };
Test.update({}, update, opts, function(error) {
Test.updateOne({}, update, opts, function(error) {
assert.ok(error.errors['numbers']);
assert.ok(error.errors['docs']);
// acquit:ignore:start
Expand Down
8 changes: 4 additions & 4 deletions test/document.strict.test.js
Expand Up @@ -266,7 +266,7 @@ describe('document: strict mode:', function() {
var doc = s.toObject();
doc.notInSchema = true;

Strict.collection.insert(doc, {w: 1}, function(err) {
Strict.collection.insertOne(doc, {w: 1}, function(err) {
assert.ifError(err);
Strict.findById(doc._id, function(err, doc) {
assert.ifError(err);
Expand Down Expand Up @@ -300,15 +300,15 @@ describe('document: strict mode:', function() {
var doc = s.toObject();
doc.notInSchema = true;

Strict.collection.insert(doc, function(err) {
Strict.collection.insertOne(doc, function(err) {
assert.ifError(err);

Strict.findById(doc._id, function(err, doc) {
assert.ifError(err);
assert.equal(doc._doc.bool, true);
assert.equal(doc._doc.notInSchema, true);

Strict.update({_id: doc._id}, {$unset: {bool: 1, notInSchema: 1}}, {strict: false},
Strict.updateOne({_id: doc._id}, {$unset: {bool: 1, notInSchema: 1}}, {strict: false},
function(err) {
assert.ifError(err);

Expand Down Expand Up @@ -338,7 +338,7 @@ describe('document: strict mode:', function() {
var doc = s.toObject();
doc.notInSchema = true;

Strict.collection.insert(doc, {w: 1}, function(err) {
Strict.collection.insertOne(doc, {w: 1}, function(err) {
assert.ifError(err);

Strict.findById(doc._id, function(err, doc) {
Expand Down
10 changes: 5 additions & 5 deletions test/document.test.js
Expand Up @@ -834,7 +834,7 @@ describe('document', function() {
var Task = db.model('gh4001', taskSchema);

var doc = { name: 'task1', title: 'task999' };
Task.collection.insert(doc, function(error) {
Task.collection.insertOne(doc, function(error) {
assert.ifError(error);
Task.findById(doc._id, function(error, doc) {
assert.ifError(error);
Expand Down Expand Up @@ -2138,13 +2138,13 @@ describe('document', function() {

var badUpdate = {$set: {'user.email': 'a'}};
var options = {runValidators: true};
Event.update({}, badUpdate, options, function(error) {
Event.updateOne({}, badUpdate, options, function(error) {
assert.ok(error);
assert.equal(error.errors['user.email'].kind, 'regexp');

var nestedUpdate = {name: 'test'};
var options = {upsert: true, setDefaultsOnInsert: true};
Event.update({}, nestedUpdate, options, function(error) {
Event.updateOne({}, nestedUpdate, options, function(error) {
assert.ifError(error);
Event.findOne({name: 'test'}, function(error, ev) {
assert.ifError(error);
Expand Down Expand Up @@ -5252,7 +5252,7 @@ describe('document', function() {

return co(function* () {
// use native driver directly to insert an empty doc
yield Test.collection.insert({});
yield Test.collection.insertOne({});

// udate the doc with the expectation that default booleans will be saved.
let found = yield Test.findOne({});
Expand Down Expand Up @@ -5283,7 +5283,7 @@ describe('document', function() {

return co(function* () {
// use native driver directly to kill the fields
yield Test.collection.insert({});
yield Test.collection.insertOne({});

// udate the doc with the expectation that default booleans will be saved.
let found = yield Test.findOne({});
Expand Down
6 changes: 3 additions & 3 deletions test/model.field.selection.test.js
Expand Up @@ -96,7 +96,7 @@ describe('model field selection', function() {
id = new DocumentObjectId,
date = new Date;

BlogPostB.collection.insert({_id: id, title: 'hahaha1', meta: {date: date}}, function(err) {
BlogPostB.collection.insertOne({_id: id, title: 'hahaha1', meta: {date: date}}, function(err) {
assert.ifError(err);

BlogPostB.findById(id, {title: 0}, function(err, found) {
Expand Down Expand Up @@ -145,7 +145,7 @@ describe('model field selection', function() {
it('works with just _id and findOneAndUpdate (gh-3407)', function(done) {
var MyModel = db.model('gh3407', {test: {type: Number, default: 1}});

MyModel.collection.insert({}, function(error) {
MyModel.collection.insertOne({}, function(error) {
assert.ifError(error);
MyModel.findOne({}, {_id: 1}, function(error, doc) {
assert.ifError(error);
Expand Down Expand Up @@ -181,7 +181,7 @@ describe('model field selection', function() {
var BlogPostB = db.model(modelName, collection),
id = new DocumentObjectId;

BlogPostB.collection.insert(
BlogPostB.collection.insertOne(
{_id: id, title: 'issue 870'}, {safe: true}, function(err) {
assert.ifError(err);

Expand Down
2 changes: 1 addition & 1 deletion test/model.indexes.test.js
Expand Up @@ -344,7 +344,7 @@ describe('model', function() {
});
});

describe('model.ensureIndexes()', function() {
describe.skip('model.ensureIndexes()', function() {
it('is a function', function(done) {
var schema = mongoose.Schema({x: 'string'});
var Test = mongoose.createConnection().model('ensureIndexes-' + random, schema);
Expand Down
10 changes: 5 additions & 5 deletions test/model.querying.test.js
Expand Up @@ -416,7 +416,7 @@ describe('model: querying:', function() {
});
});

post.collection.insert({meta: {visitors: 9898, a: null}}, {}, function(err, b) {
post.collection.insertOne({meta: {visitors: 9898, a: null}}, {}, function(err, b) {
assert.ifError(err);

BlogPostA.findOne({_id: b.ops[0]._id}, function(err, found) {
Expand Down Expand Up @@ -1468,7 +1468,7 @@ describe('model: querying:', function() {

var blogPost = db.model('BlogPostB', collection);

blogPost.collection.ensureIndex({title: 'text'}, function(error) {
blogPost.collection.createIndex({title: 'text'}, function(error) {
assert.ifError(error);
var a = new blogPost({title: 'querying in mongoose'});
var b = new blogPost({title: 'text search in mongoose'});
Expand Down Expand Up @@ -1614,7 +1614,7 @@ describe('model: querying:', function() {

var blogPost = db.model('BlogPostB', collection);

blogPost.collection.ensureIndex({title: 'text'}, function(error) {
blogPost.collection.createIndex({title: 'text'}, function(error) {
assert.ifError(error);
var a = new blogPost({title: 'searching in mongoose'});
var b = new blogPost({title: 'text search in mongoose'});
Expand Down Expand Up @@ -1998,7 +1998,7 @@ describe('model: querying:', function() {
var BlogPostB = db.model('BlogPostB', collection);
var post = new BlogPostB();

post.collection.insert({meta: {visitors: 9898, a: null}}, {}, function(err, b) {
post.collection.insertOne({meta: {visitors: 9898, a: null}}, {}, function(err, b) {
assert.ifError(err);

BlogPostB.findOne({_id: b.ops[0]._id}, function(err, found) {
Expand All @@ -2013,7 +2013,7 @@ describe('model: querying:', function() {
var BlogPostB = db.model('BlogPostB', collection),
post = new BlogPostB();

post.collection.insert({meta: {visitors: 9898, color: 'blue'}}, {}, function(err, b) {
post.collection.insertOne({meta: {visitors: 9898, color: 'blue'}}, {}, function(err, b) {
assert.ifError(err);

BlogPostB.findOne({_id: b.ops[0]._id}, function(err, found) {
Expand Down
18 changes: 9 additions & 9 deletions test/model.test.js
Expand Up @@ -609,7 +609,7 @@ describe('Model', function() {
MyModel.findById(35, function(err, doc) {
assert.ifError(err);

doc.deleteOne({}, function(err) {
doc.remove({}, function(err) {
assert.ifError(err);
done();
});
Expand Down Expand Up @@ -843,7 +843,7 @@ describe('Model', function() {
post.save(function(err) {
assert.ifError(err);

BlogPost.update({title: 1, _id: id}, {title: 2}, function(err) {
BlogPost.updateOne({title: 1, _id: id}, {title: 2}, function(err) {
assert.ifError(err);

BlogPost.findOne({_id: post.get('_id')}, function(err, doc) {
Expand Down Expand Up @@ -1133,7 +1133,7 @@ describe('Model', function() {

var TestP = db.model('TestPreviousNullValidation');

TestP.collection.insert({a: null, previous: null}, {}, function(err, f) {
TestP.collection.insertOne({a: null, previous: null}, {}, function(err, f) {
assert.ifError(err);
TestP.findOne({_id: f.ops[0]._id}, function(err, found) {
assert.ifError(err);
Expand Down Expand Up @@ -3306,7 +3306,7 @@ describe('Model', function() {
});

describe('#exec()', function() {
it('count()', function(done) {
it.skip('count()', function(done) {
var BlogPost = db.model('BlogPost' + random(), bpSchema);

BlogPost.create({title: 'interoperable count as promise'}, function(err) {
Expand Down Expand Up @@ -3340,7 +3340,7 @@ describe('Model', function() {
});
});

it('update()', function(done) {
it.skip('update()', function(done) {
var col = 'BlogPost' + random();
var BlogPost = db.model(col, bpSchema);

Expand Down Expand Up @@ -3428,7 +3428,7 @@ describe('Model', function() {
});

describe('promises', function() {
it('count()', function(done) {
it.skip('count()', function(done) {
var BlogPost = db.model('BlogPost' + random(), bpSchema);

BlogPost.create({title: 'interoperable count as promise 2'}, function(err) {
Expand Down Expand Up @@ -3902,7 +3902,7 @@ describe('Model', function() {
}
};

M.collection.insert(o, {safe: true}, function(err) {
M.collection.insertOne(o, {safe: true}, function(err) {
assert.ifError(err);
M.findById(o._id, function(err, doc) {
db.close();
Expand Down Expand Up @@ -3995,7 +3995,7 @@ describe('Model', function() {
it('path is cast to correct value when retreived from db', function(done) {
var schema = new Schema({title: {type: 'string', index: true}});
var T = db.model('T', schema);
T.collection.insert({title: 234}, {safe: true}, function(err) {
T.collection.insertOne({title: 234}, {safe: true}, function(err) {
assert.ifError(err);
T.findOne(function(err, doc) {
assert.ifError(err);
Expand Down Expand Up @@ -4076,7 +4076,7 @@ describe('Model', function() {
describe('unsetting a default value', function() {
it('should be ignored (gh-758)', function(done) {
var M = db.model('758', new Schema({s: String, n: Number, a: Array}));
M.collection.insert({}, {safe: true}, function(err) {
M.collection.insertOne({}, {safe: true}, function(err) {
assert.ifError(err);
M.findOne(function(err, m) {
assert.ifError(err);
Expand Down

0 comments on commit 37a9d8a

Please sign in to comment.