0

I am using Netlify recommended FaunaDB.

This is my update query:

  const response = await client.query(
  q.Let(

    {

      matchRef: q.Select([0], q.Paginate(q.Match(q.Index("sub_search_by_auth"), auth)))

    },

    q.Update(q.Var("matchRef"), {subscription}) // do I need to put the sub inside a data property?

  )

); 

say I have a record in db:

{
  "ref": Ref(Collection("subscriptions"), "275059653136613888"),
  "ts": 1598577889893000,
  "data": {
    "endpoint": "https://fcm.googleapis.com/fcm/send/djvbe6Pbu-Q:APA91bGicad",
    "keys": {
      "p256dh": "BJ99-332131df",
      "auth": "12332dfsdfsdfs"
    }
  }
}

I updated its keys.p256dh from BJ99-332131df to BJ99-332131dfOOOOAAA and added an new property called extra, so it looks like:

{
  "ref": Ref(Collection("subscriptions"), "275059653136613888"),
  "ts": 1598577889893000,
  "data": {
    "endpoint": "https://fcm.googleapis.com/fcm/send/djvbe6Pbu-Q:APA91bGicad",
    "keys": {
      "p256dh": "BJ99-332131dfOOOOAAA",
      "auth": "12332dfsdfsdfs"
    },
     "extra": {
         "email": "my@email.com"
     }
  }
}

Then use the aforementioned update query to update this record.

The only change I can see is the ts, nothing else.

halfer
  • 19,824
  • 17
  • 99
  • 186
Franva
  • 6,565
  • 23
  • 79
  • 144
  • To be clear to elaborate on Jays answer, everything that is not in data is meant for FaunaDB specific fields ('ts', 'ref', 'credentials' etc). Fields that are not placed in data are ignored except if they are one of these special fields. Might be confusing at first if you use the dashboard UI to add a document since there it does not require you to add everything under the 'data' key. The dashboard does that for you. – Brecht De Rooms Aug 31 '20 at 13:55

1 Answers1

2

Yes, you need to have your update wrapped in data. Hope this link helps.

Jay
  • 91
  • 1