Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #6922 fix typo in model.js #7036

Merged
merged 1 commit into from Sep 21, 2018
Merged

fixes #6922 fix typo in model.js #7036

merged 1 commit into from Sep 21, 2018

Conversation

lineus
Copy link
Collaborator

@lineus lineus commented Sep 21, 2018

re #6922 there's a typo in @5.2.16, useCreateIndex vs createIndex that causes any direct call to createIndexes ( barring the workaround below ) to always use the deprecated ensureIndexes method.

As the variable name is internal only ( it gets added to options when using createIndex directly ) and only causes a deprecation warning, I didn't add any new tests for this change.

All current tests pass.

repo script:

indexExample.js

#!/usr/bin/env node
'use strict';
const assert = require('assert');
const mongoose = require('mongoose');
mongoose.set('useCreateIndex', true);
const URI = 'mongodb://localhost:27017/test';
const OPTS = { useNewUrlParser: true, useCreateIndex: true };
mongoose.connect(URI, OPTS);
const conn = mongoose.connection;
const Schema = mongoose.Schema;

const schema = new Schema({
  name: {
    type: String,
    index: { unique: true, background: false }
  }
}, { autoIndex: false });

const Test = mongoose.model('test', schema);
const test = new Test({ name: 'test' });

async function run() {
  await conn.dropDatabase();
  await Test.createIndexes().catch(console.error);
  await test.save();
  let found = await Test.findOne();
  assert.ok(found);
  return conn.close();
}

run();

Output before change:

issues: ./indexExample.js
Mongoose: 5.2.16
(node:1979) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.
issues:

Output after change:

issues: ./indexExample.js
Mongoose: 5.2.17-pre
issues:

Temporary Workaround

You can pass an options object with useCreateIndexes: true as the first parameter to Model.createIndexes().

like:

let opts = { useCreateIndex: true }
Model.createIndexes(opts)

and circumvent the issue until the next release.

Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for catching this.

@vkarpov15 vkarpov15 added this to the 5.2.17 milestone Sep 21, 2018
@vkarpov15 vkarpov15 merged commit ff0f2dc into Automattic:master Sep 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants