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

Unable to drop unique index on collection field after schema modification #14945

Open
3 tasks done
akshdev1998 opened this issue Oct 9, 2024 · 5 comments
Open
3 tasks done
Labels
help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity

Comments

@akshdev1998
Copy link

akshdev1998 commented Oct 9, 2024

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

8.7.0

Node.js version

v22.6.0

MongoDB server version

6.9.0

Typescript version (if applicable)

No response

Description

Prerequisites

  • I have written a descriptive issue title[x] I have searched existing issues to ensure the bug has not already been reported

Mongoose version

8.7.0

Node.js version

22.6.0

MongoDB server version

6.9.0

Typescript version (if applicable)

5.6.2

Description

Description: I encountered an issue where I was unable to drop the unique index on the employeeId field in my MongoDB collection, even after modifying the schema to remove the unique constraint. The behavior suggests that the unique index on the employeeId field remained intact despite my attempts to remove it.

Steps to Reproduce

Steps to Reproduce:

  1. Create a schema with a unique index on employeeId.
  2. Try to drop the index using Mongoose.
  3. Change the schema name.
  4. Attempt to drop the index again.

Steps to Reproduce

Steps to Reproduce:

  1. Create a schema with a unique index on employeeId.
  2. Try to drop the index using Mongoose.
  3. Change the schema name.
  4. Attempt to drop the index again.

Expected Behavior

Expected Behavior:
The index on employeeId should be dropped successfully.

Actual Behavior:
The index could not be dropped, and the schema modification was ineffective.

Code Example:

const XrInteractionSchema = new mongoose.Schema({
  employeeId: { type: String, unique: true },
  // other fields
});
// for taking this issue
```javascript
const XrInteractionSchema = new mongoose.Schema({
  employeeId: { type: String, },
  // other fields
});
@akshdev1998 akshdev1998 changed the title Unable to drop unique index on employeeId after schema modification Unable to drop unique index on collection field after schema modification Oct 11, 2024
@vkarpov15
Copy link
Collaborator

Can you please clarify how you're doing "Try to drop the index using Mongoose." - are you just removing the index from your schema, are you using syncIndexes(), are you doing something else?

@vkarpov15 vkarpov15 added the needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity label Oct 11, 2024
@akshdev1998
Copy link
Author

I am removed indexes from the schema but still it is giving referencing old schema... so the issue with this

First i save with unique true

const XrInteractionSchema = new mongoose.Schema({ employeeId: { type: String, unique: true }, // other fields });

Final Schema is this but mongodb is referencing previous code

const XrInteractionSchema = new mongoose.Schema({ employeeId: { type: String, }, // other fields });

SO WHY IT IS HAPPENING

Copy link

github-actions bot commented Nov 5, 2024

This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions bot added the Stale label Nov 5, 2024
Copy link

This issue was closed because it has been inactive for 19 days and has been marked as stale.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 10, 2024
@vkarpov15 vkarpov15 reopened this Nov 20, 2024
@vkarpov15
Copy link
Collaborator

Have you disabled autoIndex option? mongoose.set('autoIndex', false): https://mongoosejs.com/docs/guide.html#indexes

@vkarpov15 vkarpov15 added help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary and removed Stale labels Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity
Projects
None yet
Development

No branches or pull requests

2 participants