Venkat
Venkat

Reputation: 841

How to do Collection Field Unique in Meteor JS?

I need to know about collection field unique in meteor js. I have created one collection as shown below:

  List= new Meteor.Collection("list");

The above collection contains 5 fields they are listed below :

 1. User Name

 2. Email

 3. Name

 4. Qualification

 5. Status

In the above fields i need to do unique are User name & Email.So is there any procedure for unique fields in a collection or do manually checking when ever inserts data to a collection each & every time.Please suggest me what to do for this above problem?

Upvotes: 7

Views: 3862

Answers (2)

juliancwirko
juliancwirko

Reputation: 1282

You can try Collection2 with SimpleSchema:

!: https://github.com/aldeed/meteor-collection2

2: https://github.com/aldeed/meteor-simple-schema

Upvotes: 1

Andrew Mao
Andrew Mao

Reputation: 36900

Create unique indices on the server. This way, Mongo checks it for you:

List._ensureIndex({username: 1}, {unique: 1});
List._ensureIndex({email: 1}, {unique: 1});

See how Meteor does it for Meteor.users: https://github.com/meteor/meteor/blob/devel/packages/accounts-base/accounts_server.js#L1136

Upvotes: 14

Related Questions