Match(Index('getUserById'), req.author.id) is going to return a Set containing 0 or 1 references (I’m guessing based on your code) to documents in Collection('users'). There’s no need to build a Reference yourself, since Set is already returning them for you. And creating the reference the way you did doesn’t make sense anyways, since it requires a string or a number, but the Match operation returns a Set (hence the error). Exists() checks for both Document existence and whether Sets are empty or not, so this code should work:
app.get('/start', async (req, res) => {
const start = Date.now();
const userExists = await db.query(
Exists(
Match(Index('getUserById'), req.author.id)
)
);
if (userExists) {
res.send('You alreay have a account!');
return;
}
db.query(Create(Collection('users'), { data: { id: req.author.id } })).then(
() => {
res.send(`Finished, it took me ${Date.now() - start}ms!`);
}
);
});
But beyond that, there’s no need to split up the two queries, you can do both of them together in a single transaction using code like this: