How to get data from two or more mongo schema in a single api call in feathersJs?

957 Views Asked by At

i have configured a basic fathers setup with two services, users and messages(with mongoose) all API endpoints are working. but how do i create an extra endpoint in a service?

i am confused how would i develop a complete webapp only using the default feathers REST endpoints.. for example i have to use an api where i need to get data from two or more mongo schema in a single api call. if i deal it in outside of feathers and use expess routing for this how would i setup the feathers authentications for these new created express routes.. please advise me a best solution my situation.

2

There are 2 best solutions below

0
On

You can try looking into GraphQL to handle such queries. You can use it to create a query that fetches data from multiple mongo schemas. Here's a feathers-graphql tutorial that can guide you: https://medium.com/@mattchewone/graphql-with-feathersjs-4cc67e785bd

0
On

As explained in the basics guide, Feathers services do not have to be tied to a single collection. In fact, a service does not even have to make database calls at all. You can implement the service interface and make calls to as many collections/models as you want. The chat application guide also shows how to associate data using hooks and further information for that can also be found in this FAQ.