没有Schema.ObjectId的猫鼬中的DB-ref? [英] DB-ref in mongoose without Schema.ObjectId?

查看:63
本文介绍了没有Schema.ObjectId的猫鼬中的DB-ref?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中,人可以跟随其他人. 到目前为止,除了这个事实之外,其他一切都还可以:在userScheme中,我拥有此字段.

in my code people can follow other people. So far everything is ok apart from this fact: in the userScheme I have this field.

, following: [{ type: Schema.ObjectId, ref: 'Users' }]

由于每个用户都有一个用户名,所以对我来说,使用带用户名的dbref更为通用. 有办法做这样的事吗?

Since every user has an username, it's more versatile for me to use dbref with the username. is there a way to do something like this?

, following: [{ type: Users.username, ref: 'Users' }]

非常感谢, g

推荐答案

否,只能将引用另一个集合的_id属性的ObjectId值用作引用.

No, only ObjectId values that refer to the _id property of another collection can be used as refs.

源代码中确认.

这篇关于没有Schema.ObjectId的猫鼬中的DB-ref?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆