javascript - After Dropping Collection, Collection is re-made when saving first records, but why aren't its indexes? -
below method dropping mongodb collection. works, after saving first records collection re-created without appropriate indexes.
since model has 3 properties unique: true
, need indexes created, no duplicates saved. why aren't instances being created, , how auto-create them?
model:
var objectschema = new schema({ propertyone: { type: string, required: true, unique: true, trim: true }, propertytwo: { type: string, required: true, unique: true, trim: true }, propertythree: { type: string, required: true, unique: true, trim: true } });
method - dropping collection
exports.dropcollection = function(collectionname, callback) { console.log("dropping collection: " + collectionname); // drop in collection name string var collection = mongoose.connection.collections[collectionname] collection.drop(function(err) { if (err) { console.log(err); callback(err, null) } else { console.log("collection deleted") callback(); } }); }
the simple reason dropped collection , indexes attached
collection. question reverse of existing post:
in mongodb, if collection dropped, indexes dropped automatically well?
what want remove. no arguments or empty query document remove documents in collection. indexes remain.
Comments
Post a Comment