I've tried to use different variation of model.find(), but none do what I want.
code below is what I'm working with, but it displays every single field, and I only want the "iframe" field.
app.get('/api/videos', function (req, res) {
Video.find({}, function (err, docs) {
res.json(docs);
});
});
Code below does work and I only get the 'iframe' field, but it reverses the json output and I don't want that. It also get unique values, even though it's not that important since every entry is unique.
app.get('/api/videos', function (req, res) {
Video.find().distinct('iframe', function (err, docs) {
res.json(docs);
});
});
W
You can use the
projection
parameter to specify which field you would like to include in the result.When you include a field you can only explicitly exclude fields in the case of the
_id
field.What you are looking for is called projection:
The second parameter to the
find
function tells which field to return. If you do not want the_id
as well, then use:{_id:0, iframe:1}
Like so:
However, projection does not give you distinct values. It only returns the fields you want to use (along with repetitions).