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

75
Views
MongoDB filter after populate javascript

I'm newer of nodejs, and I want to create API for my porfolio.

I have built API to get all of projects data, and I want to filter which use query after populate.

Project schema

const ProjectSchema = new mongoose.Schema({
  name: {
    type: String,
    required: true,
  },
  description: {
    type: String,
  },
  tags: [
    {
      type: Schema.Types.ObjectId,
      ref: "tag",
    },
  ],
  createAt: {
    type: Date,
    default: Date.now,
  },
});

Tag schema

const TagSchema = new mongoose.Schema({
  name: {
    type: String,
    required: true,
  },
  projects: [
    {
      type: Schema.Types.ObjectId,
      ref: "project",
    },
  ],
  createAt: {
    type: Date,
    default: Date.now,
  },
});

if ?tags=react, rwd I wish return:

[ 
   {
     name: "A Project",
     description: "blablabla",
     tag: [
       { name: "react" },
       { name: "rwd" },
       { name: "antd" ),
     ]
     createdAt: "2022/2/15"
   }, 
   {
     name: "B Project",
     description: "blablabla",
     tag: [
       { name: "react" },
       { name: "rwd" },
       { name: "mui" ),
     ]
     createdAt: "2022/2/15"
   },     
]

this is my code below:

// ?tags=react, rwd
const tags = req.query.tags.split(",");
const data = await Project.find()
      .sort({ number: -1 })
      .populate({
        path: "tags",
        select: "name -_id",
        match: { name: { $in: tags } },
      });

Can somebody help me to figure it out? thanks!

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!