问题
I'm using Meteor and have a question about overriding the default behavior of what type Meteor uses for User ID's.
I would like users to be uniquely identified by a _id
field of type ObjectId instead of whatever type Meteor defaults to (string?). Is there something like a configuration parameter somewhere I can set in order to have this be the case?
回答1:
Short answer:
You cannot use Objectd for the _id
property of the users
collection.
Long answer:
This has been posted as a bug report at github but unfortunately rejected.
The rationale for the rejection is, while open to debate, that core packages need some design decisions towards simplicity and robustness. They do have a point, so do the developers who +1 this bug report (I'm one of them).
There has also been a pull request to resolve another issue, while addressing this one, but that also got rejected due to some incompatibilities.
If you are really in need of a solution that requires ObjectId's all over, your safest bet is to create your own accounts package, which you can do by forking the original one towards your needs.
In fact my comment at that issue suggests a quick and dirty fix on the source code where the user's id is checked during the login flow which expects a string. You can for the package and change that check to accept ObjectId.
来源:https://stackoverflow.com/questions/24964005/using-mongo-objectid-type-for-meteor-user-ids