Skip to content

Instantly share code, notes, and snippets.

@rckrueger
Created November 6, 2020 13:07
Show Gist options
  • Save rckrueger/a03793c204dff0e506d8163d6f189ed5 to your computer and use it in GitHub Desktop.
Save rckrueger/a03793c204dff0e506d8163d6f189ed5 to your computer and use it in GitHub Desktop.
exports = async function(currentUserId, friendUserId) {
const mongodb = context.services.get("mongodb-atlas");
const users = mongodb.db("CustomUserDB").collection("CustomUserData");
let user = await users.findOne({userId: currentUserId});
let friendUser = await users.findOne({userId: friendUserId});
var chatPartition = currentUserId + "_" + friendUserId;
if (currentUserId > friendUserId) {
chatPartition = friendUserId + "_" + currentUserId;
}
var userChatPartitions = { "$push": {
"chatPartitions": chatPartition
}
};
users.updateOne({_id: user._id}, userChatPartitions, {upsert: false});
var friendUserChatPartitions = { "$push": {
"chatPartitions" : chatPartition
}
};
users.updateOne({_id: friendUser._id}, friendUserChatPartitions, {upsert: false});
return chatPartition;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment