Assert uniqueness in MongoDB - node.js

I'm using Node, Express and MongoDB (with Mongoskin) for a webbapp.
New client accounts are created through a web form, requiring inputs such as 'Company', 'Contact person', 'Email' et cetera...
When creating new clients there are some fields that have to be unique when saving to the database.
This inputs are: 'Company', 'Slug' and 'Email'
Company needs to be unique.
Slug is generated from the company name, and also needs to be unique.
Ex. 'Café Rosegarden' and 'Cafe Rosegarden' are two different company names, but will generate the same slug: 'cafe-rosegarden'.
Email. I think this need to be unique... but I'm actually not sure
Right now i have three single unique indexes on these fields.
Question 1: Is indexes the only (best?) way to assert uniqueness on a field?
Question 2: I'f im using a compound index, how does it handle uniqueness? Can i for example say that email only has to be unique in combination with one specific company name?

Yes, adding a unique index to a field is almost always the best way to ensure its uniqueness in the collection.
When using a compound index, MongoDB ensures that each doc in the collection has a unique combination of field values. So if you only had a compound unique index over company and email, you could have more than one doc with the same company or email, just as long as the combination of the two is unique.

Related

Arcade expression to calculate unique IDs in ArcGIS Pro

Arcade expression to calculate unique ID in ArcGIS Pro
I have a field that I want to be automatically populated with a unique ID whenever a new record is created. I'm pretty rusty at working with Arcade and Attribute Rules. I've figured out how to make a number automatically populate through a sequence and attribute rule, but I don't know how to make the rule take into account the values already in the table.
Using NextSequenceValue, the rule will add an ID that is unique to the new sequence that I created, but it is not unique from the other records that already have IDs. This is an old dataset with loads of different IDs that don't necessarily follow a predictable pattern, otherwise I would just choose my sequence start appropriately (some IDs are in the 100s, some in the 1000s, some even 100,000s, etc.).
I basically want to perform a check where the rule assesses if the ID is unique and if it's not, it adds 1 or something until it is unique.
I tried using a sequence but it doesn't take into account already existing IDs so they aren't truly unique.

Unique Constraint in Couchdb

Is there any way to apply unique constraint in couchdb?
Suppose I have a document which have some fields like email, emp_id, phone_number that needs to be unique throughout the document. I could not find any way. Anyone knows how to achieve this?
Any answer/suggestion would be appreciated.
after a lot of searching, I found that If you want to add a unique constraint to only one parameter you can set it as id. But If there are multiple parameter that needs to be unique, then this is not possible in couchdb
The only unique constraint in CouchDB is on the document ID. If you can put the unique components of your data in the document ID, then you have a uniqueness constraint.

Shoudl I create seperate column family if I want to query on many columns ? or use composite PK?

I have a column family like
object
(
obect_id,
company-id,
group_id,
family_id,
description,
..
);
I want to query that based on object id, company id ,group id and any combination of these.
My question is
should i make composite primary key
(object id, company id ,group id)
or create seperate column familis ?
only object id is unique in CF, company id can repeat in multiple rows, but group iddoes not repeat in many rows
You may well want to duplicate your data in multiple CFs depending on your query patterns. This is quite common practice.
If a common query is "Get all objects by company_id" then you might want to store all objects with in a CF with partitioned just by company_id as a row key. If you need to do individual object lookups as well, then you store that data duplicated in another CF - each object partitioned by object_id. If groups are always a subset of a specific company, perhaps you want to row key by company, but then cluster by group.
You should be designing your Cassandra schema based on the queries you need to run, rather than the data that needs to go in it.

how can I add a domain to a related field in openerp?

how can i add a domain to a relational field so it'll only show a list of products whose values are > 0 in openerp. Sorry am still learning programming with openerp. Thank you for you help
In your current object from which you are creating relationship with product.product, say for ex, its many2one relation, so in that case,
'product_id': fields.many2one('product.product', 'Product', domain=[('VALUE','>',0)])
VALUE means the product field on which, you want to add condition. By doing this, when you will click on that product field, it will list out only those products who are matching with your domain.

SharePoint Lookup field, what is it?

SharePoint Lookup field, what is it?
Please share, thanks.
It is a type of field used to indicate that the possible values of a column in a list must be taken from the elements of another list. For example, if you have a list of users, and one column of this list is the country, you can create a lookup field pointing to another list "countries" which contains the possible values to select.
If you think in terms of relational databases, a lookup field is a foreign key: you only store a reference to the related item, not its value.
For instance, you have a list of meeting rooms. You can create a meeting calendar by creating a new calendar list with a lookup to the "Meeting rooms" list. Hence, when organizing a meeting, you will be able to pick a room from the list of meeting rooms entered previously.
A "Lookup" differs from "Choice" field as you may alter the source item and the referencing item is updated automatically. For instance, you change the name of a meeting room - all meetings booked for that room will show the new title automatically.

Resources