Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Referencing documents #47

Closed
silently opened this issue Jan 14, 2014 · 5 comments
Closed

Referencing documents #47

silently opened this issue Jan 14, 2014 · 5 comments

Comments

@silently
Copy link

Hello, this is more a question than an issue:
what "type" should be set when we want to reference another doc within a Schema?

I've tried:

schema: {
  userId: {
    type: Meteor.Collection.ObjectID
  }
}

But got a failed validation.

Thanks!

@aldeed
Copy link
Collaborator

aldeed commented Jan 14, 2014

If your intent is to store a link to a doc in Meteor.users, I think it uses String _id by default.

@aldeed
Copy link
Collaborator

aldeed commented Jan 14, 2014

The more general answer to your question is: you're doing it correctly. If userId is an instance of Meteor.Collection.ObjectID, it should not fail validation.

@silently
Copy link
Author

Ok you were right: with a type String it works. I guess IDs are populated as Meteor.Collection.ObjectID but are stored as String in mongo.

Thank you!

@robinnewhouse
Copy link

For anyone else who lands here it looks like SimpleSchema.RegEx.Id is the way to acomplish this now with stricter validation than just String

@zhe1ka
Copy link

zhe1ka commented Feb 29, 2020

if you want to use Mongo.Collection.ObjectID then you always need to specify blackbox: true

_id: { type: Mongo.Collection.ObjectID, blackbox: true },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants