Faunadb: Create doc to a collection from a child database

125 views Asked by At

Need help. My code just runs to an error. It says: Cannot write a scoped ref.
Maybe it has to do with:

q.Collection("Projects", q.Database("Apps"))

Here's my code:

let data = {
  project: {
    id: 9273727,
    name: "test",
    author: "Matthieu"
  },
  content: []
}
client.query(q.Create(q.Collection("Projects", q.Database("Apps")), {data}))
  .then(res => console.log(res))
  .catch(error => console.log(error));
1

There are 1 answers

0
Eigil On BEST ANSWER

The error is correct. You can't do writes with scoped refs. Only read. You have to initiate your client with a secret that belongs to the database you want to write in. If you have a admin key you can create a scoped secret. Format it like so {{serverKey}}:{{dbName}}:{{role}}. Role could be admin or any other role.