0

I am new to couchbase and couchnode. Considering couchnode Documentation, upsert callback function only return err and CAS. I want to get updated or inserted object in response. How can I do this?

Below is documentation detail for upsert function.

upsert(tuples, [options,] callback) → Bucket

  • tuples: tuple (object with keys and respective values)
  • options: object

    • cas: The CAS value to check. If the key on the server contains a
      different CAS value, the operation will fail. Note that if this
      option is undefined, no comparison will be performed. For details on passing the CAS token for each of the keys, check Per key options.

    • expiry (default 0): Expiration time of the key. If it's equal to zero, the item will never expire. You can also use Unix timestamp or a number of seconds starting from current time, but in the latter case the number of seconds may not exceed 2592000 (30 days).persist_to

    • (default 0): Ensure this operation is persisted to this many nodes.
    • replicate_to (default 0): Ensure this operation is replicated to this many nodes.
  • callback(err, cas)
    • cas: object with keys and respective CAS token.
Jahanzaib Aslam
  • 2,731
  • 3
  • 21
  • 26

1 Answers1

1

If the upsert operation is successful, the upserted object is the exact same value you passed to upsert in the first place. There is no point to duplicating this information.

If your callback is inside a closure, you can always reference the object you passed to upsert.

Mark Nunberg
  • 3,551
  • 15
  • 18
  • Thanks @mnunber but if i have auto increment ID for my each new document. after successful insertion i also need that ID in final response. how can i get that ID? – Jahanzaib Aslam Jul 29 '15 at 05:15
  • Couchbase does not have a concept of an auto-increment ID. If you have an auto-increment ID, it is done somewhere in your application and you should have a record of this in your application code. You can make auto-increment IDs using couchbase counters, but in this case anytime you increment a counter you get the value back in return. – Mark Nunberg Jul 29 '15 at 18:17