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 · 2 comments
Open
3 tasks done
Labels
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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