-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
4.11.0: useMongoClient:true incompatible with config.autoIndex #5423
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
Comments
I'd also like to see this fixed/cleared. |
Documentation states to put autoIndex at the root level. In Mongoose 4.11.14 which apparently has the bugfix for this issue, Mongoose ignores the autoIndex parameter (building indexes against the config's direction) and passes it to MongoDB Client. I moved it to config: { autoIndex: false } while keeping everything else at the root level and this resolved the issue. Unsure if this will also be an issue in 5.X https://mongoosejs.com/docs/4.x/docs/connections.html#options
|
@DevBrent in the latest version of 4.x ( 4.13.17 ), the error 5423_5.js on ( [email protected] )#!/usr/bin/env node
'use strict';
const mongoose = require('mongoose');
const { Schema, connection} = mongoose;
const GH = 'gh5423';
const URI = `mongodb://localhost:27017/${GH}`;
const OPTS = { useNewUrlParser: true, autoIndex: false };
const schema = new Schema({
name: {
type: String,
unique: true
}
});
const Test = mongoose.model('test', schema);
const test = new Test({ name: 'test1' });
async function run() {
await mongoose.connect(URI, OPTS);
await connection.dropDatabase();
await test.save();
let indexes = await Test.collection.listIndexes().toArray();
console.log(indexes);
await connection.close();
}
run(); Output:
5423_4.js on ( [email protected] )#!/usr/bin/env node
'use strict';
const mongoose = require('mongoose');
mongoose.Promise = global.Promise;
const { Schema, connection } = mongoose;
const GH = 'gh5423';
const URI = `mongodb://localhost:27017/${GH}`;
const OPTS = { useMongoClient: true, autoIndex: false };
const schema = new Schema({
name: {
type: String,
unique: true
}
});
const Test = mongoose.model('test', schema);
const test = new Test({ name: 'test1' });
async function run() {
await mongoose.connect(URI, OPTS);
await connection.dropDatabase();
await test.save();
let indexes = await Test.collection.listIndexes().toArray();
console.log(indexes);
await connection.close();
}
run(); Output:issues: ./5423_4.js
[ { v: 2, key: { _id: 1 }, name: '_id_', ns: 'gh5423.tests' } ]
issues: |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
If the current behavior is a bug, please provide the steps to reproduce.
The guide at: http://mongoosejs.com/docs/guide.html states, with respect to auto-indexing:
... it is recommended this behavior be disabled in production since index creation can cause a significant performance impact. Disable the behavior by setting the autoIndex option of your schema to false, or globally on the connection by setting the option config.autoIndex to false.
After upgrading to 4.11.0, with
config.autoIndex: false
set on the connection options, the following warning is emitted:(node:79221) DeprecationWarning:
open()
is deprecated in mongoose >= 4.11.0, useopenUri()
instead, or set theuseMongoClient
option if usingconnect()
orcreateConnection()
After adding
useMongoClient: true
to the connection options, the following is emitted:the options [config] is not supported
What is the expected behavior?
I'm not sure; I realize this is an in-flux situation. The API documentation and guide seem to be out of sync with one another and it's unclear if the ability to globally disable autoIndexing via a connect() option is still available.
I do hope it still is; it's great peace of mind for production environments, but it'd be error-prone to have to handle this on each schema, rather than globally.
Please mention your node.js, mongoose and MongoDB version.
Node 6.10.2, Mongoose 4.11.0, MongoDB 3.2.11.
The text was updated successfully, but these errors were encountered: