Skip to content Skip to sidebar Skip to footer

How Can I Create My Mongodb Query Based On The Input From The User In Node.js?

Currently in my app I store different forum posts. Users can add new messages and create new posts. Other users - while displaying the content - can filter it so that they will not

Solution 1:

If I understood well:

  • If user has a banned device_id, then block him
  • If user has a banned display_name, then block him

In that case, it does not really matter if he is anonymous or not.


let excludedUsernames, excludedDevices;

blockedUsers.forEach((e) => {
    excludedUsernames.puhs({ e["display_name"] });
    excludedDevices.push({ e["device_id"] });
});

query.$and.push({ 'display_name' : { $nin: excludedUsernames } });
query.$and.push({ 'device_id'    : { $nin: excludedDevices   } });

EDIT

query.$or.push({
    $and: [
        { 'device_id'    : { $nin: excludedDevices }},
        { 'display_name' : "anonymous" }
    ]
});
query.$or.push({ 'display_name' : { $nin: excludedUsernames } });

Post a Comment for "How Can I Create My Mongodb Query Based On The Input From The User In Node.js?"