Rahul_Dabhi
Rahul_Dabhi

Reputation: 730

mongoose index creation issue after drop collection

I had created one index on the collection and it was created. But after the drop that collection and when I restarted node server then collection are created again but the index isn't can anybody suggest what is the cause?

const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const validator = require('validator')

const FeatureSchema = new Schema({
    name:{
        type: String, 
        trim: true,
        required: "Please enter a feature name!"
    },
    slug: String,
    description: {
        type: String,
        trim: true
    },
    author: {
        type: mongoose.Schema.ObjectId,
        ref: 'User',
        required: 'You must supply an author'
    },
    productID: {
        type: mongoose.Schema.ObjectId,
        ref: 'Product',
        required: 'You must supply an product'
    }
},{
    timestamps: {
        createdAt: 'createdDate',
        updatedAt: 'updatedDate'
    }
});

// Define our indexes
FeatureSchema.index({
    name: 'text'
});

module.exports = mongoose.model('Feature', FeatureSchema);

Upvotes: 0

Views: 149

Answers (1)

Setu Modi
Setu Modi

Reputation: 100

try to stop mongodb service and restart it again.

Upvotes: 1

Related Questions