简体   繁体   English

如何关闭 mongoose 中的严格填充?

[英]How to turn off strictpopulate in mongoose?

How can you populate something that is not in the schema?您如何填充模式中不存在的内容? Mongoose is throwing the error Cannot populate path 'example' because it is not in your schema. Set the 'strictPopulate' option to false to override. Mongoose 抛出错误Cannot populate path 'example' because it is not in your schema. Set the 'strictPopulate' option to false to override. Cannot populate path 'example' because it is not in your schema. Set the 'strictPopulate' option to false to override.

I tried adding strictPopulate: false to the Schema and the query.我尝试将strictPopulate: false添加到架构和查询中。 Both didn't work.两者都不起作用。

It seems this works for me这似乎对我有用

 document.populate([{ path: keyString, strictPopulate: false }]);

Suppose you have a product orderItem inside orderList .假设您在orderList中有一个产品orderItem You can't populate producy when reading orderList , instead you can use:阅读orderList时不能填充产品,而是可以使用:

.populate({ path: "orderItems", populate: "product" });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM