嗨,我正在根据时间删除我的数据库。我正在使用 cron 设置时间并删除数据库。下面是代码
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]);
});
});
}
当我运行上述代码时,我无法删除我的收藏。以下是错误消息
TypeError: Cannot call method 'remove' of undefined
任何想法如何解决这个问题都会非常有帮助