Source: lib/db/users/writes.js

  1. import { ObjectID } from "bson";
  2. import { getUsersCollection } from "../mongodb";
  3. /**
  4. * Updates a user's account with the provided data.
  5. *
  6. * @param {string} userId
  7. * @param {object} data
  8. */
  9. export async function updateUser(userId, data) {
  10. const collection = await getUsersCollection();
  11. const result = await collection.updateOne(
  12. {
  13. _id: ObjectID(userId),
  14. },
  15. {
  16. $set: {
  17. ...data,
  18. },
  19. }
  20. );
  21. return result;
  22. }