如何在JavaScript中使用.populate()
的集合
CR
我有一个名为“我想做的事情”
let cre = await CR.find({myid: "xxxxxx"})
就是这样查询:而且我还有一个称为 cla
的集合,但是我需要根据 cre
/代码>。 CRE的结果将返回一个class_id,在其中我需要用来查询 cla
集合以查找 _id
。在所有这些结束时,我想理想地合并两者,我相信您可以通过 .populate()
进行操作,然后将其发送到Teh前端。
我已经尝试过:
let cre = await cr.find({myid: "xxx"}).populate('loc').populate('desc').populate('dt');
但这不起作用。我该如何解决?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能是由于图式造成的,但这是干净且易于使用的方式。
It may be due to schemas, but this is how it's clean and simple to use;
首先,您可以在 cr 收集模式中采用 cla 收集“ _id”。在 cr 集合的模式中,请参阅 cla模型ID ,
然后您可以像这样填充,
希望这将解决您的问题。
注意:在填充时,您可以按空格给出多个列名,如果您在这样的列名之前给出负名(-columnname),那么该列将无法显示何时调用API。
Firstly, you can take cla collection "_id" in CR collection schema. In schema of CR collection refer to cla model id like this,
Then you can populate like,
Hopefully, this will solve your issue.
Note: There in populating you can give multiple column names by space and if you give a minus before a column name like this (-columnName) then that column will not show when you will call the API.