Comments (3)
Unless something has changed with MongoDB, I believe this is a limitation at the database level. Believe you can enforce the index from the parent document - but this will apply across the parent's collection with something like:
class Foo
include Mongoid::Document
embeds_many :bars
index "bars.token", unique: true
end
class Bar
include Mongoid::Document
include Mongoid::Token
embedded_in :foo
token
end
But, again - this is enforced across the Foo collection, so you'd need to take that into consideration when choosing the structure for your tokens.
from mongoid_token.
Thanks, this is a bug in mongodb, and there is no way to define a proper unique index for this scenario. Please feel free to close this issue.
from mongoid_token.
Thanks - yeah it's pretty frustrating.
Previously we were leveraging Rails validations to enforce uniqueness, and whilst it handled this case it was substantially slower - and I think maybe even subject to race conditions (at least at the time).
from mongoid_token.
Related Issues (20)
- Generate tokens for old Documents? HOT 1
- another define_method() issue? HOT 4
- Feature Request: Add rake or inline rails ability to generate tokens
- undefined method `args' in token.rb HOT 1
- Am I using mongoid_token incorrectly? or is this a bug? HOT 4
- Rails Admin has_many relations fail to save HOT 4
- Please specify a licence HOT 2
- Gem naming HOT 1
- not working in embed document? HOT 2
- Can i use token as foreign key? HOT 4
- Readme should say `bundle install` not `bundle update` HOT 1
- Is there any plans for mongoid 5? HOT 2
- Is there a way to generate token without saving the actual document
- Feature Request: allow regenerate_token HOT 2
- Class.clone yields NoMethodError HOT 3
- Allow Mongoid 5.1
- Mongoid 6 support HOT 3
- uninitialized constant Mongoid::Token::Collisions
- Feature: Human friendly token generation (Idiot proof)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongoid_token.