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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -