I am developing an realtime application (node, socket.io and mongoDB with Mongoose) which receive data every 30 seconds. The data received is some metadata about the machine and 10 pressures.
I have a document per day that is preallocated and I have to update the data every 30 seconds, i.e the pressures for the time 15:02:00.
The doc in MongoDb looks like:
{
metadata: { .... }
data: {
"0":{
"0":{
"0":{
"pressures" : {.....},
},
"30":{}
},
"1":{},
"59":{}
},
"1":{},
"23":{}
}
},
Preallocate this data with a save is expensive, around 700 miliseconds.
I know that using:
entity.markModified(path);
entity.save()
Is possible to update data in Mixed fields so in my case I could do:
entity.data[time.hour][time.minute][time.second].pressures = data.data.pressures;
entity.save()
But the problem is that making a save for update only a field of 2880 fields (24hours * 60 minutes * 2 seconds ) inside the data field is still very expensive, around 450ms.
So I want to know if there is a way to use update instead of save with markModified to achive a cheap update, around 10 ms, or any other way to achive this goal
PD: I've taken a look at this link Pre-Aggregated Reports about real-time app with MongoDB and there is an example making updates (in python) with the update command (cheap operation), but it looks that it can’t be done with mongoose.
I would appreciate any help
Thanks