question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting unique: true won't work

See original GitHub issue

Hi, I have setup a field to be unique using unique: true. I’m trying to validate it in the client and use invalidKeys() to get all the errors. But I can’t see the uniqueness error in there! Looks like it will allow me to add duplicate values?

I’m trying to set one field to be unique using simple schema. But no matter what I do it’s not working. Here’s how I set it up :

let schema = new SimpleSchema({
  name: {
    type: String,
    label: 'Committee name',
    max: 200
  },
  shortName: {
    type: String,
    label: 'Short name',
    max: 10,
    index: true,
    sparse: true,
    unique: true,
    autoValue: (com) => {
      if (com.shortName) {
        return com.shortName.toLowerCase();
      }
    }
  },
});

I even tried to reset meteor. If I add a duplicate value, it won’t add the record but won’t even give any errors when validating.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:8

github_iconTop GitHub Comments

1reaction
Murukaencommented, Jan 27, 2017

+1

1reaction
thesubr00tcommented, May 24, 2018

Hi @aldeed,

I’ve installed aldeed:meteor-collection2 wich automatically install simple-schema & schema-index.

But still no validation for ‘unique’

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why @Column(unique = true) does not work? - Stack Overflow
It create object in entity. Problem is because I can multiply this object again and again instead of unique = true in columns...
Read more >
Setting unique: true won't work #605 - GitHub
I'm trying to set one field to be unique using simple schema. But no matter what I do it's not working. Here's how...
Read more >
Model field reference - Django documentation
If the built-in fields don't do the trick, you can try django-localflavor ... One exception is when a CharField has both unique=True and...
Read more >
UNIQUE function - Microsoft Support
Learn about the UNIQUE function, which returns a list of unique values in a list or range. UNIQUE is in a class of...
Read more >
Unique partial index is not working with mongoose on email
I tested this (with or without mongoose-unique-validator) by setting 'terms_accepted' to true and false, email index doesn't work on saving ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found