I'm trying to make a 'like' route that find user by _id then query inside user.post an object id, so far I tried this:
User.find({
    "_id": logged_user,
    "posts_id": {
        $elemMatch: req.body.id
    }
}, (err, data) => {
    if (err) {
        res.json(err)
    }
    console.log(data);
})
Schema:
 username: String,
 posts:[{
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User'
 }]
it returns an empty array '[]', how can I return true of false if it exists?
 
     
    