Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

94
Vistas
How to get fixed amount of documents from mongodb?

Now my code is returning all the news related to a company. But I want only the first 15 elements. How to do this? Here is the code which returns all the news for a company. google-news-json is a npm package.

export default async function handler(req, res) {
  try {
    let news = await googleNewsAPI.getNews(googleNewsAPI.SEARCH, req.body.companyName, 'en-US')
    res.status(200).json(news)

  } catch (err) {
    res.status(500).json({ error: 'Failed to fetch news' })
  }
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You need to take a close look at the API reference of google news functionality. There you can find a query parameter ( something like ?q=15 or ?count=no.of.items ) after your API key to return the count of object that you may want to receive in the fetch url

about 4 years ago · Juan Pablo Isaza Denunciar

0

Typically you'd want to do what @iceweasel suggests in their answer. However, since this package isn't supported by Google (but rather seems to be scraping the HTML produced by directly querying Google News and returning the results as JSON), it doesn't support many of the typical options you'd expect (in particular, limiting the number of returned elements).

If you don't mind the network cost of downloading the full 100 items (which is what your function returns by default), you take the first 15 results from the API's response with:

let top15 = news.items.slice(0, 15)

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda