如何在猫鼬中填充许多模式
请在这里给我解决方案 我打算编写一个共享搜索查询的通用函数,我使用mongodb + mongoose,
但是有一个我不知道如何动态使用pupulate()的问题。
例如:
const findData = async(model, populate, params) => {
return await model
.find(params)
.populate() //issue????
};
我想填充许多其他模式,但仍然找不到将填充填充到此功能的方法(即:我可以在调用此功能时通过它传递的模式)? 谢谢你建议我 非常感谢
Please give me the solution here
I'm planning to write a common function to share for search queries, I use MongoDB + Mongoose
But there is a problem that I don't know how to dynamically use populate().
Ex:
const findData = async(model, populate, params) => {
return await model
.find(params)
.populate() //issue????
};
I want to populate to many other Schemas but still can't find a way to pass populate to this function dynamically (ie: I can populate to the Schema it is passed in when calling this function)?
Thank you for suggesting me
Many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在一个数组中收集所有填充命令,并在每个人查询中召集并使用。
you can collect all populate command in one array and called in .populate and use if for everyone query and add push new command in your array and all of them send your array of populate in your mongoose query like :