node.js - blocked user Json Query for mongodb -
i have 3 post in collection of 3 different user trying fetch post in views session (html, css) part need filter other 2 post posted other 2 user because have block functionality in view section. post allowed user have blocked her/his post not visible me , mine him.
blockedbyuser : (this post json data)
{ "_id" : objectid("591729b52bb30a19afc9b89d"), "createdtime" : isodate("2017-05-13t15:43:49.381z"), "isdeleted" : false, "message" : "message two", "postedby" : objectid("598adbefb3bf0b85f92edc3b"), "recipient" : [ objectid("598ae453b3bf0b85f92ee331"), objectid("5910691ae2bcdeab80e875f0") ], "updatedtime" : isodate("2017-05-20t09:24:39.124z") }
below 2 user post data have blocked , in recipient array key stores id recipient [598adbefb3bf0b85f92edc3b]
block user 1 :
{ "_id" : objectid("591729b52bb30a19afc9b89d"), "createdtime" : isodate("2017-05-13t15:43:49.381z"), "isdeleted" : false, "message" : "message one", "postedby" : objectid("598ae453b3bf0b85f92ee331"), "recipient" : [ objectid("598adbefb3bf0b85f92edc3b"), objectid("5910691ae2bcdeab80e875f0"), objectid("598ac93cb3bf0b85f92ece44"), ], "updatedtime" : isodate("2017-05-20t09:24:39.124z") }
same above block user 2 :
{ "_id" : objectid("591729b52bb30a19afc9b89d"), "createdtime" : isodate("2017-05-13t15:43:49.381z"), "isdeleted" : false, "message" : "message one", "postedby" : objectid("598ac93cb3bf0b85f92ece44"), "recipient" : [ objectid("598adbefb3bf0b85f92edc3b"), objectid("5910691ae2bcdeab80e875f0"), objectid("598ae453b3bf0b85f92ee331") ], "updatedtime" : isodate("2017-05-20t09:24:39.124z") }
this block collection have created , 2 blocked user id blockuserid key block details 1 :
{ "_id" : objectid("598da2f0b88b0c2b0c735234"), "blockuserid" : objectid("598ae453b3bf0b85f92ee331"), "blockbyid" : objectid("598adbefb3bf0b85f92edc3b"), "updateddate" : isodate("2017-08-11t12:28:32.145z"), "createddate" : isodate("2017-08-11t12:28:32.145z"), "isblock" : "true", "__v" : 0
block details two
{ "_id" : objectid("598da558b88b0c2b0c735236"), "blockuserid" : objectid("598ac93cb3bf0b85f92ece44"), "blockbyid" : objectid("598adbefb3bf0b85f92edc3b"), "updateddate" : isodate("2017-08-11t12:38:48.772z"), "createddate" : isodate("2017-08-11t12:38:48.772z"), "isblock" : "true", "__v" : 0 }
i have fetch these blocked collection , store 2 user blockuserid id in array arrone = ["598ae453b3bf0b85f92ee331", "598ac93cb3bf0b85f92ece44"]
and applying query in mongoose db:
query = {$or: [{$and: [{ $or: [{ postedby: req.params.id}, {recipient: req.params.id} ] }, { createdtime: { $gt: endtime, $lt: starttime } } ]},{postedby: {$ne: arrone}} ] }; }
but return undefined value trying fetch post or other user post not blocked me, , blocked user post not visible me
i have implement clause , works
var query = { $and: [{ $or: [{ postedby: req.params.id }, { recipient: req.params.id }] }, { "createdtime": { $gt: endtime, "$lt": starttime } }] }; collectionname.find(query).where('postedby').nin(blocklist).exec(function(err, response);
Comments
Post a Comment