Uploaded image for project: 'Couchbase Documentation'
  1. Couchbase Documentation
  2. DOC-6110

Error in function code snippet given in his example

    XMLWordPrintable

Details

    Description

      on this page we are creating below function:

      function OnUpdate(doc, meta) {
      if (meta.expiration > 0 ) //do only for those documents that have a non-zero TTL
      {
      var expiry = new Date(meta.expiration);
      // Compute 2 minutes from the TTL timestamp
      var expiry = new Date(meta.expiration);
      // Compute 2 minutes from the TTL timestamp
      var twoMinsPrior = new Date(expiry.setMinutes(expiry.getMinutes()-2));
      var context =

      {docID : meta.id}

      ;
      createTimer(DocTimerCallback, twoMinsPrior , meta.id, context);
      .....
      }

      problem here is with the line var expiry = new Date(meta.expiration);
      because new Date() takes milliseconds as an arguments, but meta.expiration stores TTL in seconds.

      This example will always cause the timer to go off immediately.

      Solution: we can do var expiry = new Date(meta.expiration * 1000); or store TTL in milliseconds.

      Reporter: sushil kumar
      E-mail: sushil_kumar1@homedepot.com

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            amarantha.kulkarni Amarantha Kulkarni (Inactive)
            docsite-collector Docs Site Collector
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty