Being new to MongoDB, I have created the following schemas:
const postSchema = new mongoose.Schema(
{
content: { type: String, required: true, index: "text" },
author: { type: ObjectId, ref: "User", required: true, index: true }
}
);
const muteWordSchema = new mongoose.Schema({
word: { type: String, trim: true, required: true },
match: { type: String, enum: ["exact", "contains", "startsWith", "endsWith"], required: true },
});
My goal is to:
- Retrieve all posts
- Retrieve all muted words
- Convert the muted words into corresponding regular expressions. For example,
will be transformed into{ word: "test", match: "startsWith" }
/(^|\s)test/g
, and so on. - Filter out posts that match these transformed regular expressions.
How can I accomplish this task using aggregation pipelines?