I have been working on creating a social network that allows users to send and interact with friend requests. Currently, I have completed the registration, log-in, and "search for other users" functions.
Once I find and select another user, I am able to display their user information and have added an "Add friend" button.
However, I am struggling to find the right solution for implementing the "Add friend" feature. I have spent some time searching for solutions but have not found the correct one yet. Below, you will find my UserSchema and the route for finding users:
//User Schema
const UserSchema = new mongoose.Schema({
firstName: {
type: String,
required: true
},
lastName: {
type: String,
required: true
},
password: {
type: String,
required: true
},
},{ collection: 'Users' });
//Get single user based on ID
router.get('/user/get:id', ensureAuthenticated, function (req, res) {
MongoClient.connect(DBUri,{useUnifiedTopology: true }, function (err, db) {
let dbo = db.db(DBName);
const query = {_id: objectId(req.params.id)}
dbo.collection("Users").find(query).toArray(function(err, resultTasks) {
if (err) throw err;
res.render('../View/findFriend', {
resultTasks: resultTasks
});
db.close();
});
});
});