couchbasecouchbase-lite

How to avoid Keys with Duplicate Values in Couchbase.Lite


Is it possible to tell CB.Lite to reject documents that contain values from a certain key repeated?

For instance, if i have the next document already in CB.Lite:

{
  "Dog": {
    "Name": "Dug",
    "Color": "Blue",
    "Age": 2
  }
}  

Is it possible to tell CB.Lite to reject any document with repeated Key "Name", so that if i try to add the next one:

{
  "Dog": {
    "Name": "Dug",
    "Color": "Green",
    "Age": 5
  }
}  

it would reject it?

I know It would be not much hassle to implement this functionality myself, but i was wondering if CB.Lite has already something Out of the Box.


Solution

  • Currently not at commit time (this is as of 1.4.x). The closest you could where Couchbase would do most of the work would be to create a View emitting the value you don't want repeated, then query and do the enforcement yourself.

    This is assuming the docs themselves have different IDs. If you had what you showed using the same document ID, there are other possibilities. For example, you could trap this and reject it in Sync Gateway.