My post schema looks like this.
const Post = new Schema({
author: String,
view: Number,
point: Number,
title: String,
images: [Schema.Types.Mixed],
content: String,
tags: [String],
comments: [{ displayName: String, body: String, createdAt: Date }],
createdAt: {
type: Date,
default: Date.now
},
editedAt: Date
})
And my query is:
Post.statics.findByTags = function(tags) {
return this.find({
tags: { $in: tags }
}).
limit(10).
sort({ createdAt: -1 }).
exec()
}
What I'm trying to do is match posts which have one of the tags provided by parameter "tags".
ex) if tags equals ["tag1", "tag2"] and
Post1 = { ...some values, tags: ["tag1"]}, Post2 = { ...some values, tags: ["tag1", "tag2"]}
I want to match both posts.
I'm using Postman to test those queries and now I'm getting nothing except an empty array.