Nodejs + Mongojs: convert string to document

I'm trying to insert a new document into my collection, by getting the data from url and i have to sew them together, so at the end i have a string. How can i convert my string into a document?

var x={name:"peter"}; 

This works fine if i pass it to the insert function.

var x='{name:"peter"}'; 

This is what i have, and i would like to pass this somehow to insert.

Use JSON.parse()

Read more about it here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse

Node.js has JSON by default, so you can just use it.

Example:

var object = JSON.parse("{hello:'world'}");

will give you an object which you can persist to MongoDB.