How to query Users in Functions?

I am trying to check if a User is Registered. But for this I need to access somehow Users from Functions.

exports = async function(partition) {
    // Current User
    const user = context.user;
    // Atlas
    const db = context.services.get("mongodb-atlas").db("Objects");

    // Users how to get ???
    const db = context.services.get("users ....");
};

Hi Alex,

If I understand correctly you’re asking how to query for a user in your collection and compare the current user to see if it exists.

You can use MQL in the function. Quick example below:

exports = function(user) {
  
  const user = context.user;

  const usersCollection = context.services.get("mongodb-atlas").db("Objects").collection("users");
  
  return usersCollection.find({"_id" : user })

};

See documentation below for more details.

Regards