Im coming from using mongoDB so will use this as an example, in it I can do something like.
collection.ensureIndex('id', {unique: true, dropDups: true });
And then whenever I try to insert data with the same id, I will get a duplicate key error and it wont work. great!
But can a similar thing be done with documentDB?
Currently I have the following code written with node.js to insert data:
client.createDocument(collection_id, data_to_insert, function (err, doc) {
callback(err, doc);
});
DocumentDB does not have native support for defining unique constraints. The id
property is a special exception in which it is the primary key for a document and must be unique.
You can leverage DocumentDB's triggers to implement a unique constraint on other document properties. I have a sample trigger on Github here.
From an indexing perspective - every attribute in every document is automatically indexed by default. If you wish to tune specifically which paths get indexed and which do not, you can define a custom index policy on a collection level.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With