问题描述
我正在使用Meteor,并且有一个关于覆盖Meteor用于用户ID的类型的默认行为的问题.
I'm using Meteor and have a question about overriding the default behavior of what type Meteor uses for User ID's.
我希望用户由ObjectId类型的_id
字段唯一标识,而不是由Meteor默认设置为(string?)的任何类型.我可以在某处设置某个配置参数,以使这种情况成为现实吗?
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?
推荐答案
简短答案:
您不能将Objectd用作users
集合的_id
属性.
You cannot use Objectd for the _id
property of the users
collection.
详细答案:
此消息已发布为在github上的错误报告,但不幸的是被拒绝了.
This has been posted as a bug report at github but unfortunately rejected.
拒绝的理由是,尽管尚有争议,但核心程序包需要一些设计决策,以实现简单性和鲁棒性.他们确实有道理,对这个错误报告+1的开发人员也是如此(我就是其中之一).
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.
如果您确实需要一种需要ObjectId的解决方案,那么最安全的选择就是创建自己的帐户包,您可以通过根据需要打包原始帐户包来完成.
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.
实际上,在该问题上的我的评论表明对源代码进行了快速而肮脏的修复在登录流程中检查用户ID(需要一个字符串)的位置.您可以获取该软件包,然后更改该检查以接受ObjectId.
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.
这篇关于使用Mongo ObjectId类型作为流星用户ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!