-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Index not created when using ascending or descending #13725
Comments
For me its not creating the index because its throwing an error. const mongoose = require('mongoose');
const testSchema = new mongoose.Schema({
name: String
});
testSchema.index({ createdAt: "ascending" }, { unique: true });
const Test = mongoose.model('Test', testSchema);
async function run() {
await mongoose.connect('mongodb://localhost:27017/gh13725');
await mongoose.connection.dropDatabase();
await Test.init();
await Test.create({
name: 'Test Testerson'
});
}
run();
|
If we do not call the Test.init() function it does not throw any kind of error. In the documentation it says as follows - When we add Test.init() it throws the error but the type system still recommends the ascending,asc,etc. options. Try running following code :-
|
fix(schema): support 'ascending', 'asc', 'descending', 'desc' for index direction
Prerequisites
Mongoose version
7.4.1
Node.js version
18.6.1
MongoDB server version
6.0.8
Typescript version (if applicable)
5.1.6
Description
I have recently observed an issue when creating index on mongoose Schema using the
index()
method.When I assign the value to a field as ascending or descending as recommended by Typescript Intellisense the index is not created in the database.When I replace it with numerical representations such as
1 or -1
it does work as expected and the index is created.Steps to Reproduce
orderSchema.index({ createdAt: "ascending" }, { unique: true })
Expected Behavior
The index should be created according to specified value. If ascending is specified it must be created in ascending order and vice versa.
The text was updated successfully, but these errors were encountered: