I have a nodeJS app and im using mongoDB to store some data like: 1. usrID, 2. usrName 3. Friends list[is an array]
using nodeJS how do i go to the collection "users" and then add to the array of someone with a specific usrID
This is some code that I have:
exports.makeFriendRequest = function(from, to){
mongo.connect(mongoDB, function(err, db) {
if (err) throw err;
var dbo = db.db("My database");
var from = from;
var to = to; //the userID array that we want to change
var collection = dbo.collection('users');
collection.insert(obj);
//dont know what to do here to add to the array
});
}
i have an array with friends for each user and i want to be able to add a string which is another userID to represent that they are "friends" how would i do that?