0

i am trying go convert my json array in to simple (numbered)values. getting them from database(.find), the problem is they are not converting with json.parse. am i doing something wrong?

 Voltage.find({},function (err, data) {
        var jsontext = data;
        var parsedData = JSON.parse(jsontext);
        res.json(parsedData);
        console.log(parsedData);
    });

ths is the console.log for the session, i was hoping for just: 333, 333, 333 etc.

[{"_id":"56f3c19a0298308405d60464","temp":333,"__v":0},{"_id":"56f3c1ee7ec57884068dcb2c","temp":333,"__v":0},{"_id":"56f3c4467ec57884068dcb2d","temp":333,"__v":0},{"_id":"56f3d80191a3c68c138bf04d","temp":337,"__v":0},{"_id":"56f3da3f06cefa781763fb21","temp":337,"__v":0}]

it is the temp values i am trying to get out to send to my front end only. i am using mongooose, express.js and node.js with a mongodb also. thanks for looking.

1 Answer 1

1

One thing you could do is deselect them in the query:

 Voltage.find().select('-_id -__v').exec(function (err, data) {
        var jsontext = data;
        var parsedData = JSON.parse(jsontext);
        res.json(parsedData);
        console.log(parsedData);
    });

Read up on the select method here.

Sign up to request clarification or add additional context in comments.

2 Comments

thats great, thanks. that has narrowed it down a bit,i need to give the value if temo over as a var '333' . any idea how to do that? thanks again
i am getting back this message upon parsing {undefined:1 { temp: 333 },{ temp: 333 },{ temp: 333 },{ temp: 333 },{ temp: 333 },{ temp: ^ SyntaxError: Unexpected token t at Object.parse (native)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.