You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do you want to request a feature or report a bug?
Feature What is the current behavior?
Hi, I've two problems about indexes, the first one is I use soft delete, so if I've a unique index, I need to add an partialFilterExpression to avoid problems.
Now I've a plugin to spread data to make partitions, so my plugin adds a _zone field, but in this plugin I need to change all the indexes generated in the schemas, I've no problem duplicating the indexes but my problem is the unique indexes, because now the unique index must include the _zone field.
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
I need to be able to modify the indexes generated in the schema, so the plugin can add the field to every index. What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
node: v16.4.1
mongodb: 4.4.6
mongoose: 5.13.2
The text was updated successfully, but these errors were encountered:
vkarpov15
added
help
This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
and removed
new feature
This change adds new functionality, like a new method or class
labels
Jul 13, 2021
You can modify schema indexes in place by looping over schema.indexes() and modifying each index as shown below.
'use strict';constmongoose=require('mongoose');mongoose.set('useFindAndModify',false);const{ Schema }=mongoose;run().catch(err=>console.log(err));asyncfunctionrun(){awaitmongoose.connect('mongodb://localhost:27017/test',{useNewUrlParser: true,useUnifiedTopology: true});awaitmongoose.connection.dropDatabase();constschema=newSchema({email: String,isDeleted: {type: Boolean,default: false}});schema.index({email: 1},{unique: true,partialFilterExpression: {isDeleted: false}});schema.plugin(schema=>{schema.add({_zone: String});// Loop over every index in the schemafor(constindexofschema.indexes()){if(index._zone!=null){continue;}// Add `_zone` as the first key in the indexindex[0]={_zone: 1, ...index[0]};}});console.log(schema.indexes());}
vkarpov15
added
docs
This issue is due to a mistake or omission in the mongoosejs.com documentation
and removed
help
This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
labels
Aug 9, 2021
Do you want to request a feature or report a bug?
Feature
What is the current behavior?
Hi, I've two problems about indexes, the first one is I use soft delete, so if I've a unique index, I need to add an partialFilterExpression to avoid problems.
Now I've a plugin to spread data to make partitions, so my plugin adds a _zone field, but in this plugin I need to change all the indexes generated in the schemas, I've no problem duplicating the indexes but my problem is the unique indexes, because now the unique index must include the _zone field.
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
I need to be able to modify the indexes generated in the schema, so the plugin can add the field to every index.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
node: v16.4.1
mongodb: 4.4.6
mongoose: 5.13.2
The text was updated successfully, but these errors were encountered: