Using mongodb with node.js serial port communication

375 views
Skip to first unread message

Nikhil Raman

unread,
Jul 28, 2015, 8:13:44 PM7/28/15
to mongodb-user
Hey!

I have an application where I have 4 sensors connected to the arduino. The arduino is connected to my computer over USB and I have a node.js server running with a mongodb instance. 
I have the data being parsed in the serialport section of node.js and basically, the data coming out of the parser is of this format:

"Temperature": <data>,
"Humidity": <data>,
"Pressure": <data>,
"Light":<data>

I would like to put all this data into a mongodb collection as the data comes in. 
When I try to do this, I get an error which says: "cannot assign to read-only property "_id" of Temperature: "

Can anyone tell me how I can get around this error? I basically have the field name and data for that field both coming in from the arduino and would like to update the mongodb collection as such.

Thanks in advance!
Nikhil

Stephen Steneker

unread,
Jul 28, 2015, 9:29:14 PM7/28/15
to mongodb-user, nik...@gmail.com, nik...@gmail.com
Hi Nikhil,

The error message suggests your application code is trying to update an existing read-only `_id` property. It's not clear if that message is coming from the MongoDB driver or elsewhere in your Node.js code, but a good starting point would be to check your Node.js stack trace.

If the stack trace points at the MongoDB driver, someone may be able to help further if you can post more details such as:
 - specific Node.js driver version used
 - example data and a code snippet that is setting the values
 - schema definition if you are using an ODM (i.e. Mongoose)

Regards,
Stephen

Nikhil Raman

unread,
Jul 29, 2015, 4:56:32 PM7/29/15
to mongodb-user, ste...@mongodb.com
Hi Stephen,

Going through the trace, I realized that the JSON object I was sending was not coming through correctly due to some incorrect parsing that I was doing. 
Once I got that fixed, this whole system works like a charm!

Thanks,
Nikhil 
Reply all
Reply to author
Forward
0 new messages