How do I prevent duplicate documents from being inserted during very rapid transactions?

36 views
Skip to first unread message

Daniel W

unread,
Apr 27, 2017, 2:12:23 PM4/27/17
to RavenDB - 2nd generation document database
I have multiple, separate applications that may insert the same document into the same table at nearly the same moment.  I've been able to work around this in testing by hashing a semantic key from a number of fields in the document, but this feels like a hack.  I would LIKE to just query to check if a document with the same key exists prior to inserting, but I haven't been able to get this working.  Any suggestions?

Oren Eini (Ayende Rahien)

unread,
Apr 27, 2017, 2:23:27 PM4/27/17
to ravendb
You can use optimistic concurrency for this, or the unique key bundle.


Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


On Thu, Apr 27, 2017 at 7:42 PM, Daniel W <dan.wa...@gmail.com> wrote:
I have multiple, separate applications that may insert the same document into the same table at nearly the same moment.  I've been able to work around this in testing by hashing a semantic key from a number of fields in the document, but this feels like a hack.  I would LIKE to just query to check if a document with the same key exists prior to inserting, but I haven't been able to get this working.  Any suggestions?

--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel W

unread,
Apr 27, 2017, 3:50:36 PM4/27/17
to RavenDB - 2nd generation document database
If I used the Unique Constraint bundle, and I have a number of fields defining the "uniqueness" of a document, would I do something like this?

public class MyDocument{
   
[UniqueConstraint]
   
public Tuple<long, string, string> MyUniqueConstraint { get { return new Tuple<long, string, string>(ReleventField1, ReleventField2, ReleventField3); } }
   
public long RelevantField1 {get;set;}
   
public string RelevantField2 {get;set;}
   
public string RelevantField3 {get;set;}
   
// other fields
}
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.

Oren Eini (Ayende Rahien)

unread,
Apr 27, 2017, 4:00:00 PM4/27/17
to ravendb
Yes, each field defined is unique.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages