Created
November 6, 2020 13:07
-
-
Save rckrueger/a03793c204dff0e506d8163d6f189ed5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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