Search code examples
javascriptrethinkdbthinky

Enforce uniqueness in thinky (rethinkdb)


In the thinky.io docs the following pattern is described to enforce uniqueness:

var Model = thinky.createModel("user",
    name: type.string()
}, {
    pk: "name"
});

Where the name property is assigned to the primary key.

Is this a typo? That is, should it read:

var Model = thinky.createModel("user", {
    name: type.string()
}, {
    pk: "name"
});

Also for anyone familiar with thinky who has used this pattern before, is there a similar way of assigning uniqueness as it is done in mongoose (mongodb):

const userSchema = new Schema({
    name: { type: String, unique: true }
});

Thanks.

Update: link to the docs https://thinky.io/documentation/faq/


Solution

  • Yes, definitely a typo as the first example is not valid.