MongoDB : Unique value
See original GitHub issueHello,
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:
- Created 3 years ago
- Reactions:2
- Comments:5 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
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 asallowNull: false
in my program (as well as insert documents with duplicate unique fields, as stated).