How do I query an array within loopback 3?
I have the following method:
Driver.reserve = async function(cb) {
let query = {
where: {
preferred_delivery_days: {
elemMatch: {
availability: 0
}
}
}
};
return await app.models.Driver.find(query);
};
But I am getting the following error:
code: ER_PARSE_ERROR
errno: 1064
sqlMessage: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''{\"availability\":0}' ORDER BY `id`' at line 1
sqlState: 42000
sql: SELECT
driver021489826505814413.`first_name`,driver021489826505814413.`last_name`,driver021489826505814413.`gender`,driver021489826505814413.`preferred_delivery_days` FROM `my_driver_table` driver021489826505814413 WHERE driver021489826505814413.`preferred_delivery_days`'{\"availability\":0}' ORDER BY `id`
Here is an example of a database entry:
[
{
"day": 5,
"time": "morning",
"availability": 0
}
]
I think it might be hard, since according to the docs :
Data source connectors for relational databases don't support filtering nested properties.
If your project is in the starting phase you may consider to change db to mongo or other no-sql db?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.