【mongoose】populate 如何关联到非 _id 字段?

new Schema({
    pid: {type: String, ref: ‘product’},
    sid: {type: String, ref: ‘sale’},
}));

假设有 productsale 两个集合

pid 和 sid 指定的都是 product 和 sale 集合的 user_id 而不是 _id

用 populate 填充 总是把 pid 和 product 的 _id 关联上了,然后就查询不出来

有什么办法 pid 和 sid 指定的是 user_id 而不是 _id

求大神解答

阅读 4.1k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题