Search code examples
netlifynetlify-cmsfaunadb

FaunaDB updating records only updates ts(timestamp), nothing else changed


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": "[email protected]"
     }
  }
}

Then use the aforementioned update query to update this record.

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


Solution

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