Closed DmytroMysak closed 3 years ago
const mongoose = require('mongoose');
(async function () {
const collation = { collation: { locale: 'simple' } };
const connection = await mongoose.createConnection('mongodb://localhost:27017/test-db').asPromise();
const someSchema = new mongoose.Schema({
title: String,
author: String,
});
someSchema.index({ title: 1, author: 'text' }, collation);
const model = connection.model('Some', someSchema);
mongoose.set('debug', true);
await model.syncIndexes({ background: false });
// await model.syncIndexes({ background: true});
await model.collection.dropIndexes();
await mongoose.connection.dropDatabase();
})();
Your solution was correct
Do you want to request a feature or report a bug? bug
What is the current behavior? I'm running .syncIndexes() and the mongoose is recreating text index every time.
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior? If the text index is the same, .syncIndexes() shouldn't recreate it every time.
In
isIndexEqual
we should check db index weights + key (with omiting 2 properties: _fts + _ftsx) Something like this one:What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version. node: 14.16.1 mongoose: 6.0.9 MongoDB: 4.4