I have a strange problem and I can’t understand what the problem is. The error message does not help.
I send an “alarm” to the server and want to save this alarm on my “device”, which already exists in the database.
The alarm object sent to the server is as follows:
{actionTaken: "none",
dateTime: "20152111191512",
difference: 4.88,
timestamp: 1448128894781}
The circuit for the device is as follows:
var deviceSchema = new Schema({
deviceId: {
type : String,
index : {
unique : true,
dropDups : true
}
},
alarms : [ {
timestamp : Number,
dateTime : String,
difference : Number,
actionTaken : String,
} ]
});
I load the device from the database (deviceId is installed):
Thermometer.findOne({
deviceId : deviceId
}, function(error, device){
var now = (new Date().getTime());
var nowDateTime = (new Date()).toISOString().slice(0, 19).replace(/[-T\s:]/g, "");
var newAlarm = {
timestamp : now,
dateTime : nowDateTime,
difference : diff,
actionTaken : "none"
};
device.alarms.push(newAlarm);
});
As you can see in the commentary, I get Exception / Error when I want to click the "newAlarm" object on the alarm array of my device.
: "[ ]" " "
-:
kind: "string",
message: "Cast to string failed for value "[object Object]" at path "alarms"",
name: "CaseError",
path: "alarms",
stack: undefined,
value: {actionTaken: "none", dateTime: "20152111191512", difference: 4.88, timestamp: 1448128894781}
?
. () . ?
:
"express": "3.2.6",
"express-session":"1.7.6",
"hjs": "*",
"mongoose": "4.0.5",
"nodemailer": "1.4.0"
EDIT: . . .
EDIT 2:
lastAlarm
device.lastAlarm = alarm;
.lastAlarm undefined... - . , - ?