Question is simple, but not answered perfectly yet for me (perhaps only for me but is not totaly clear..)
Question : I want to return MongoDB from "collection.findOne" with mongo.. is ok AND JSON.stringify() this informations for send to another service...
// i past a pseudo code for response :-)
collection.find({id_to_find: id_to_find}, function(err, results) {
if (err){
console.log ("error find");
}if (results) { // update for good syntax !
var results = JSON.stringify(results); // error, why ??? <if not this line, is ok, but i want stringify !>
res.json({
returnJSON: results
});
}
}
////////////////////////////////////
// example of a mongo object return :
[ { _id: 1,
property: 'xxxx',
etc: 'xx'
},
{ _id: 2
property: 'xxxx',
etc: 'xxxx'
}
]
Next time, i have severals records like results_mongo = [{mongo object datas},{ etc.. }] // like an array
i want with my server node.js to JSON.stringify my collection && return theses results..
The error is :::::
TypeError: Converting circular structure to JSON
at Object.stringify (native)
Response ?
(thank to correct object to result, my question is how to exept the stringify deep object.. :)
for searchs, a goods posts on stack : Convert Mongoose docs to json