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

330
Vistas
Mongoose: Check if value exists in string array

I am querying to get all articles that have a specific source name and category.

I have an article schema that looks like below.

The issue I'm facing is that, it fetches the articles with the correct source name, but it doesn't fetch for the right category. For example, if source is "cnn" and category is "sports", it fetches all articles from CNN correctly, but not with correct categories (the articles may have a categories of ['politics', 'culture'] with no sports)

const article_schema = new mongoose.Schema({
    title: {
        type: String, 
        required: true
    },
    thumbnail_url: {
        type: String, 
        required: true
    },
    summary: {
        type: String, 
        required: true
    },
    text: {
        type: String, 
        required: true
    },
    link: {
        type: String, 
        required: true
    },
    publish_date: {
        type: String, 
        required: true
    },
    source: {
        name: {
            type: String, 
            required: true
        },
        name_slug: {
            type: String, 
            required: true
        },
        link: {
            type: String, 
            required: true
        },
        display_picture_url: {
            type: String, 
            required: true
        },
        biography: {
            type: String, 
            required: true
        },
        tags: {
            type: [String], 
            required: true
        },
        rssFeeds: [{
            url: {
                type: String, 
                required: true
            },
            categories: {
                type: [String], 
                required: true
            }
        }]
    }
}); 
let getNews = async (req, res) => {
    const { sort, filter, current_page, limit, category_slug } = req.body;
    
    let articles = await Article.findOne({ 'source.name_slug': filter, categories: category_slug });

    res.setHeader('Content-Type', 'application/json');
    res.status(200).send({ articles });
} 
about 4 years ago · Juan Pablo Isaza
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