Skip to content

Instantly share code, notes, and snippets.

@fceller
Created April 21, 2012 16:43
Show Gist options
  • Save fceller/2438277 to your computer and use it in GitHub Desktop.
Save fceller/2438277 to your computer and use it in GitHub Desktop.
Unique Constraint
AvocadoDB shell [V8 version 3.9.4, DB version 0.3.12]
avocado> db.example.ensureUniqueConstraint("a");
{ "id" : "113199/965167", "unique" : true, "type" : "hash", "fields" : ["a"], "isNewlyCreated" : true }
avocado> db.example.save({ a : 1 });
{ "_id" : "113199/1620527", "_rev" : 1620527 }
avocado> db.example.save({ a : 1, b : 1 });
JavaScript exception in file '(avocado)' at 1,12: [AvocadoError 1210: unique constraint violated: cannot save document]
!db.example.save({ a : 1, b : 1 });
! ^
stacktrace: [AvocadoError 1210: unique constraint violated: cannot save document]
at (avocado):1:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment