https://docs.strongloop.com/display/public/LB/Fields+filter
If I have example a location property composed by
and I want show only city and state in the results
Person.find({
fields: {
id: true,
location: {
city: true,
state: true
}
}
}, function(err, people){ ... })
this will returns the whole location property
@raymondfeng Is this feature supported yet?
+1
This would be very useful
filter: {
fields: {
id: true,
'user.id': false
}
}
+1
After some investigation, this commit is in part responsible.
With the 2 blocks:
+ if (Array.isArray(options.fields)) {
+ keys = keys.filter(function(k) {
+ return (options.fields.indexOf(k) != -1);
+ });
+ }
It filters the fields (looking for the field aaa.bbb.ccc in the document and got only the first-depth field aaa) so it won't play well with nested fields.
A right solution would be to check with lodash if the path aaa.bbb.ccc exists in the document,
options.fields = options.fields.forEach(k => {
return _.has(data, k)
})
And use _.get to filter the returned data.
I think this is possible with the following syntax;
Post.find({
include: {
relation: 'owner', // include the owner object
scope: { // further filter the owner object
fields: ['username', 'email'], // only show two fields
include: { // include orders for the owner
relation: 'orders',
scope: {
where: {orderId: 5} // only select order with id 5
}
}
}
}
}, function() { /* ... */ });
@rkmax I know it's been a while but did you find a way to soluce this ?
Most helpful comment
@rkmax I know it's been a while but did you find a way to soluce this ?