I am trying to update a MongoDB collection that I have created a schema for using Mongoose. My goal is to remove all elements in an array known as 'alarms' that are less than (in the past) of the current time.
Here is my Mongoose Schema:
var mongoose = require('mongoose');
var ReminderSchema = new mongoose.Schema({
firstName: String,
lastName: String,
phone: Number,
email: String,
medication: String,
alarms: [Date]
});
module.exports = mongoose.model('Reminder', ReminderSchema);
Here is the update. I am trying to remove all alarms that are less than the current date.
var date = new Date();
var Reminder = require('./models/Reminders.js');
//remove ALL alarms that are are before current time
Reminder.update({alarms: {$lte: date}}, {$pullAll: {alarms: {$lte: date}}}, function(err, updated){
if(err){
console.log(err);
}
else {
console.log(updated);
}
});
I am currently getting this error:
{ [MongoError: $pullAll requires an array argument but was given a Object]
name: 'MongoError',
message: '$pullAll requires an array argument but was given a Object',
driver: true,
index: 0,
code: 2,
errmsg: '$pullAll requires an array argument but was given a Object' }
Any thoughts?