如何使用带有动态键的猫鼬模型架构? [英] How to use mongoose model schema with dynamic keys?
本文介绍了如何使用带有动态键的猫鼬模型架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将mongoose与nodejs一起使用,并且我需要创建一个动态模式模型, 这是我的代码:
i'm using mongoose with nodejs, and i need to create a dynamic schema model, this is my code:
schema.add({key : String});
key ="user_name",但是在我的数据库中,我发现该模型将其作为密钥
key = "user_name", but in my db i found that the model take it as key
{ key : "Michele" } and not { user_name: "Michele"}
我该怎么办?谢谢.
推荐答案
同一问题 schema with variable key
用猫鼬说话,
The same issue schema with variable key
is talked in mongoose,
目前不可以.最接近的替代方法是使用
strict: false
或mixed
模式类型.
这篇关于如何使用带有动态键的猫鼬模型架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文