Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D7E2172D5 for ; Thu, 20 Oct 2011 11:57:34 +0000 (UTC) Received: (qmail 35136 invoked by uid 500); 20 Oct 2011 11:57:33 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 35004 invoked by uid 500); 20 Oct 2011 11:57:32 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 34996 invoked by uid 99); 20 Oct 2011 11:57:32 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Oct 2011 11:57:32 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of patrick.petermair@openforce.com designates 81.223.107.118 as permitted sender) Received: from [81.223.107.118] (HELO outbound.openforce.com) (81.223.107.118) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Oct 2011 11:57:27 +0000 Received: from [IPv6:2001:15c0:6766:0:21e:c9ff:fe4e:2a36] (split.openforce.com [IPv6:2001:15c0:6766:0:21e:c9ff:fe4e:2a36]) by outbound.openforce.com (Postfix) with ESMTPSA id C7F206E0AD for ; Thu, 20 Oct 2011 13:57:04 +0200 (CEST) Message-ID: <4EA00C9D.9080906@openforce.com> Date: Thu, 20 Oct 2011 13:57:17 +0200 From: Patrick Petermair Reply-To: patrick.petermair@openforce.com User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110921 Thunderbird/3.1.15 MIME-Version: 1.0 To: user@couchdb.apache.org Subject: unique constraint in couchdb Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit hey! ist there a way to ensure some kind of unique constraint in couchdb other than the document id? for example: we have multiple documents that each represent a timestamp of a user. { user: "foobar@foo.at", timestamp: "2011-10-20T10:10" } { user: "foobar@foo.at", timestamp: "2011-10-20T11:50" } { user: "otheruser@foo.at", timestamp: "2011-08-20T08:11" } ... ... we now want to ensure, that a user can't have 2 documents with the same timestamp .. basically creating a key for user + timestamp. the solution so far is to create a view with a key of [user, timestamp] and check after every document creation/update if there are more than 1 documents for a given user + timestamp tuple. this obviously has the performance penalty of having to do a seperate db call. it also leaves the db in an inconsistent state until it is resolved. the other solution is to use the user + timestamp as document id. but this would require to update the document id whenever the timestamp is edited. are there any other solutions? is there something on the roadmap for couchdb that would solve our unique key problem? or is couchdb simply the wrong tool for the job? thanks! patrick