I'm kinda beginner with MongoDB and got task to push new values to Database, but only values to make it as a array, the thing is that current query duplicate everything, value and key, here is example:
"battery_message" : [
{
"ChargerState" : null
},
{
"ChargerStatus" : null
},
{
"OutputVoltage" : null
},
{
"timestamp" : 1561442271.976242
},
{
"ChargerState" : null
},
{
"ChargerStatus" : null
},
{
"OutputVoltage" : null
},
{
"timestamp" : 1561442302.637065
}
],
The thing is that probably some new date might appear in battery message so in my schema it looks like this:
battery_message: Array
And here is my query:
deviceControllers.updateDevice(
{device_id: message.device_id},
{$push: { battery_message: [
{ChargerState: message.data.ChargerState},
{ChargerStatus: message.data.ChargerStatus},
{OutputVoltage: message.data.OutputVoltage},
{timestamp: message.data.timestamp},
]}}
)
Basically the idea is to make later for example ChargerState: [value, value, value, etc.]