Hi!
I am using feathersjs for my system as API. When my users do api call like: api.my.site/v1/items?token=BPGhLf9D9FEM?title=Hello
It seaches in database db.items.find({title: 'Hello'});
But my db design is bit different, TITLE is stored in data object
It should run this mongo query: db.items.find({'data.title': 'Hello'});
How can I make feathers search in my data object? Is there way to override the feathers where and sort queries?
Many thanks!
Hi @perminder-klair. You can modify the request data with Hooks before they are sent to the database. In your case like this:
app.service('items').before({
find(hook) {
const oldQuery = hook.params.query;
const newQuery = {};
Object.keys(oldQuery).forEach(key => {
newQuery[`data.${key}`] = oldQuery[key];
});
hook.params.query = newQuery;
}
});
I also answered this in Slack, so I think we can close.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue with a link to this issue for related bugs.