If you want to "re-shape" your documents in this way you can use the .aggregate()
method instead of find:
collection.aggregate([
{ "$project": {
"a": 1,
"b": 1,
"c": 1,
"link": { "$concat": [
"http://api.example.com/fooobject/",
"$_id"
]}
}}
],function(err,result) {
// Output work here
})
This uses $project
to "shape" your document response by selecting and creating fields. In this case there is the use of $concat
in order to join the string with the value of the _id
field.
To add query information to your search, see the $match
operator.
For other uses, see the reference for aggregation framework operators.