Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

327
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!