如何在两个应用程序之间分享猫头鹰模型? [英] How can I share mongoose models between 2 apps?

查看:140
本文介绍了如何在两个应用程序之间分享猫头鹰模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个应用程序,每个在不同的文件夹,他们需要共享相同的模型。



我想将模型文件夹从应用程序A符号链接到模型文件夹在应用程序B中。



我遇到了一个问题,一旦你在应用程序A中调用mongoose.model('Model',Schema)有没有人有任何提示来管理这个最好的方法?

解决方案

我最后在这里做的是将app1作为子模块(使用Git)导入app2。这样,模型可以正常导入,并与应用程序的默认 mongoose 连接相关。


I have 2 apps, each in a different folder and they need to share the same models.

I want to symlink the models folder from app A to a models folder in app B.

I'm running into issues with the fact that once you call mongoose.model('Model', Schema) in app A, they are 'tied' to that app's mongoose/mongodb connection.

Does anyone have any tips on the best way to manage this?

解决方案

What I ended up doing here was importing app1 as a submodule (with Git) in app2. This way the models can be imported as normal and are tied to the app's default mongoose connection.

这篇关于如何在两个应用程序之间分享猫头鹰模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆