Reputation: 19
I have Current measuring Sensor and wants to send sensors data Based on room_no in MongoDB.
I have Room 1 Schema in Nodejs for MongoDB
var Sensor_Schema = mongoose.Schema //sensor_data schema
({
room_no: [{type:String, "default":''}],
current:[{type:String, "default":''}],
power: [{type:String, "default":''}],
},
{
versionKey: false
});
I need help in MongoDB query for sending data based on room_no. I know i have to use aggregation but unable to understand how can i use it.
Upvotes: 1
Views: 128
Reputation: 331
Below is the sample that looks like for storing sensors data. I hope this will help you
aggregate([{$group :{_id: "$room_no", pwrarr: {$push: "$power"} , crntarr : {$push:'$current'}}}])
PS:here pwrarr and crntarr are arrys
Upvotes: 1