-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Suggestion
As I wrote in #2807 (comment), it is possible to execute raw SQL queries using the recently introduced Repository method execute, see #2681. This works great for SQL connectors.
Unfortunately, this method does not work for MongoDB and possibly for other NoSQL connectors that require more than just a command string and args array.
We need to find a way how to improve LB4 API, MongoDB connector API or both, to make it easy to execute raw MongoDB commands.
Related code:
Use Cases
- execute
aggregatequery, see How to execute raw MongoDB queries #2807, How can i use mongodb aggregate with lb4? #2021
Examples
const result = dataSource.execute('MyCollection', 'aggregate', [
{
$lookup:{
.....
}
},
{ $unwind:"$data" },
{
$match:{
...
}
},
{
$lookup:{
...
}
},
{ $unwind:"$LoanRepayment" },
{ $project : { _id: 0} },
{ $out : "tempData" }
],
);Acceptance criteria
-
Improve the typedef signatures for
executepossibly with some overloading on both repository classes in LB4 (feat(repository): add support for non-SQL variants ofRepository.execute()#6030) and datasource classes in Juggler (see types: support non-SQL styles ofds.executeloopback-datasource-juggler#1855) -
Add API docs on repository classes in LB4 (feat(repository): add support for non-SQL variants of
Repository.execute()#6030) and datasource classes in Juggler (see types: support non-SQL styles ofds.executeloopback-datasource-juggler#1855) -
Create a new page about the
executemethod under https://loopback.io/doc/en/lb4/Working-with-data.html. Mention the connectors that supports theexecutemethod (see Add documentation for executing native database commands #6047) -
Add details about
executemethod on relevant pages under https://loopback.io/doc/en/lb4/Database-connectors.html.See also Add documentation for executing native database commands #6047 (review):
This is a good content to be mentioned in "Configuring DataSource" page [Spike][Docs] reorganize connector reference into reference, how-to guides, and tutorials #6061
-
Add tests to ensure raw NoSQL queries are executing as expected for MongoDB (see test: add acceptance-level tests for
repository.execute()#6046) -
Investigate why the acceptance test is failing for PostgreSQL and fix the problem, see test: add acceptance-level tests for
repository.execute()#6046 (comment)