Sunday, 1 September 2019

Custom mongoose find queries

Hey, I'm writing small social media app and I've encountered a problem that I cannot seem to solve. This is my code so farconst phrase = req.query.phrase; let result = await Post.find({ $and: [ { '$text': { '$search': phrase } }, { $or: [ { createdBy: req.user._id }, { state: 'published', privacyLevel: 'public' }, { privacyLevel: 'friendsOnly', state: 'published' } ] }] }); I want to get posts that are either:a) created by currently logged in userb) have its state set to published and privacyLevel to publicc) have its state set to published and privacyLevel to friendsOnly and (and that's what I'm struggling with) I want to somehow check if the objectID of the creator of the post (post.createdBy property) is in array friendsList that contains objectIDsIs there a way to achieve it? Can I somehow do a custom search or something like this?

Submitted September 01, 2019 at 07:44PM by Sniboyz

No comments:

Post a Comment