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.

MongoDB : Unique value

See original GitHub issue

Hello,

I’m using denodb with MongoDB, I set the unique value at true in my model, but I can insert several times the same objects. I don’t know if denodb supports the unique value for MongoDB. Someone has an idea ?

Here my code :

  static table = 'users';
  static timestamps = true; // To have a created_at and updated_at

  static fields = {
    id: {
      primaryKey: true,
      as: "_id"
    },
    email: {
      type: DataTypes.STRING,
      unique: true,
      allowNull: false
    },
    username: {
      type: DataTypes.STRING,
      unique: true,
      allowNull: false
    },
    password: {
      type: DataTypes.STRING,
      allowNull: false
    },
  };

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
eveningkidcommented, Nov 11, 2020

Hi Edwix,

Thank you for the LONG wait, I know!

After checking the code, unique values are indeed not supported for now.

I will need to work on this shortly, this shouldn’t take long.

Will keep you updated here once it’s done 😃

Keep in touch

0reactions
gabeklavanscommented, Jan 3, 2021

Not sure if this is quite on topic, but in my testing it seems that allowNull is not implemented for MongoDB, either. I can use {ModelName}.create() to insert a document with fields missing that are marked as allowNull: false in my program (as well as insert documents with duplicate unique fields, as stated).

Read more comments on GitHub >

github_iconTop Results From Across the Web

db.collection.distinct() — MongoDB Manual
Finds the distinct values for a specified field across a single collection or view and returns the results in an array. This method...
Read more >
MongoDB - Distinct() Method - GeeksforGeeks
In MongoDB, the distinct() method finds the distinct values for a given field across a single collection and returns the results in an...
Read more >
3 Ways to Return Distinct Values in MongoDB - Database.Guide
In MongoDB, the db.collection.distinct() method finds the distinct values for a specified field across a single collection or view and returns ...
Read more >
How does MongoDB Unique works with Examples - eduCBA
MongoDB's Unique Constraint makes certain that the fields indexed in it, do not store duplicate values for the same field, i.e., making sure...
Read more >
Mongodb find() query : return only unique values (no duplicates)
@HalfBloodPrince, what full record? distinct returns all the unique values for a field. Returning a record or records doesn't make sense in this ......
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