I want to select a whole document and send it as JSONObject.
app.post('/getinvbykost', function(request, response){
var tablename = request.body.tablename;
Move.find({tablename: tablename}, function(err, doc) {
response.json(doc);
});
});
This gives the correct result but with "[]" ->Array and not with {} ->JSONObject. btw: I got the same issue with Move.aggregate(pipeline, function(err, res) {...
result:
[
{
STUFF
}
]
There is a function $unwind but I dont get it....
doc[0]Or, use thefindOnemethod.docis an array, and express converts it to JSON when sending it to the client using theres.jsonmethod.#findreturns an array of documents. If you need your results to be an Object with each property corresponding to some identifying data, use _.indexBy or similar code of your own.