Check existence of a key in a bucket while using subdoc feature


I would like to see if there is an efficient way to check the existence of an arbitrary key against couchbase bucket. My use case is that I have millions of <k,v> pairs to be persisted in the bucket on a daily basis.

I figure out a way to just update the subdocument using the latest feature. However, it seems it is inevitable to check whether a key exists or not beforehand, because the subdoc-exists feature would throw exception if the key is not in the bucket.

What would be an efficient way to upsert a subdoc even the key is new?