hi I am performin a deletion of my db based on the time.I am using cron to set the time and delete the db.Below is the code
var cronJob = require('cron').CronJob;
new cronJob('* * * * *', function(){// set the required time
console.log('inside cron');
console.log(new Date());
console.log('You will see this message every minute');
dbDatadeletion();
}, null, true);
//This function performs the required operations after a particular time
function dbDatadeletion(){
var mongoose = require('mongoose');
var db1 = mongoose.createConnection('mongodb://localhost/CDB');
db1.on('error', console.error.bind(console, 'connection error:'));
db1.once('open', function callback (){
console.log('Database connectivity established...\n');
var schema = new mongoose.Schema({ USER_ID:String, APIKEY:String, SERVICE_ORCH_NAME:String, COLLATED_DATA:String });
var C_DATA_STORE = db1.model('C_DATA_STORE', schema);
var query = C_DATA_STORE.find();
console.log('Query Operation is being performed...');
query.select('COLLATED_DATA SERVICE_ORCH_NAME');
query.exec(function (err, data) {
if (err) return handleError(err);
console.log('Before Deletion');
console.log(data[0]);
db1.C_DATA_STORE.remove();
console.log('After Deletion');
console.log(data[0]);
});
});
}
When i run the above code i am not able to delete my collection.Below is the error message
TypeError: Cannot call method 'remove' of undefined
Any idea how to resolve this will be really helpful
To remove all docs from the collection:
C_DATA_STORE.remove(callback)
To drop the collection, use the driver method:
C_DATA_STORE.collection.drop(callback)
To drop the database, use the driver method:
db1.db.dropDatabase(callback)