How can i get posts by tags stored in user mode

post schema:

    const BlogSchema = new mongoose.Schema(
    {
        
        title: {
            type: String
          },
          content: {
            type: String
          },
          author: {
            type: mongoose.Schema.Types.ObjectId,
            ref: Tags
          },
          content_type: {
            type: mongoose.Schema.Types.ObjectId,
            ref: Tags
          },
          valid_until: {
            type: Date,
          },
          timestamp: {
            type: Date,
            default: Date.now
          },
    likes: { type: [String], default: [] },

    },
);

user schema:

    const mongoose = require('mongoose')

const UserProfileSchema = mongoose.Schema({
    userid: {
        type: String
    },
    firstname: {
        type: String,
        default: ''
    },
    tags: [{
        type: mongoose.Schema.Types.ObjectId,
        ref: 'Tag'
    }]
})

tag schema:

    const TagSchema = new Schema({
    name: {
        type: String
    },
    type: {
        type: Object,
    },
    color: {
        type: String
    },
    timestamp: {
        type: Date,
        default: Date.now
    },
});

this code is in post controller it will aggregate posts

    const blogs = await Blog.aggregate([
                {
                    $lookup: {
                        from: "tags",
                        localField: "author",
                        foreignField: "_id",
                        as: "blog_tags"
                    }
                }])

What can i do to make it only get posts that are in user tags

Hi @Norah_Alothman,
I am a little confused about this part of your Schema, the author should be referenced as a user, isn’t it.

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer