Manfred Tijerino
Manfred Tijerino

Reputation: 377

How can I create a Get request in Node.js to get specific object from json?

I am optimizing an api, therefore I need to use only data that is relevant for my analysis. I have created a route that pull out of the objects, but I just need 4 of them (account_manager, fronter, closer, management_fee and sales_date)

enter image description here

I am currently doing this:

enter image description here

Upvotes: 0

Views: 65

Answers (1)

Ravi Shankar Bharti
Ravi Shankar Bharti

Reputation: 9268

you can use .find() with projection to retrieve only the relevant field

try this :

const model_CancellationKPI = await CancellationKPI.find({},{
    account_manager:1, 
    fronter:1, 
    closer:1, 
    management_fee:1, 
    sales_date:1
}).sort({sales_date:-1})

Upvotes: 2

Related Questions