visionmedia/connect-redis — Issue #38: Update Array of Type Mixed
Author: Nexum
Created: 2012-01-23 09:55:45+00:00
State: open

Hi,

i'm currently trying to save an array of Informations inside a Log entry, but i just cant get it to work i want to lock the max Infomation saved to 20 rows, but it jsut doesnt work it just saves the new one... help please xD

here is my model:

```
var log = new mongoose.Schema({
Info: Array,

Type: {
type: String,
"default": "undefined"
},

Class: {
type: String,
"default": "undefined"
},

Message: {
type: String,
"default": "undefined"
},

Counter: {
type: Number,
"default": 0
},

Last: {
type: Date
}
});
```

here is my code where i update:

```
logModel.findOne({
Message: newEntry.Message
}, function (err, doc) {
if ( doc ) {
// This should lock the max length to 20 ...
if(doc.Info.length > 20) {
while(doc.Info.length >= 20) {
doc.Info.shift();
}
}
// add the new one...
doc.Info.push(newEntry.Info[0]);
doc.Counter++;
doc.Last = newEntry.Info[0].Date;

// mark modified
doc.markModified("Info");
doc.save(function (err, newdoc) {
console.log(doc.Info.length, newdoc.Info.length);
console.timeEnd('Processed Log Entry ' + currentNumber + '/' + data.length);
callback();
});
} else {
newEntry.Last = newEntry.Info[0].Date;
newEntry.save(function (err) {
console.timeEnd('Processed Log Entry ' + currentNumber + '/' + data.length);
callback();
});
}
});
```