处理猫鼬中的架构更改 [英] Dealing with schema changes in Mongoose

查看:59
本文介绍了处理猫鼬中的架构更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着应用程序的发展,更新/迁移Mongoose模式的最佳实践(或工具)是什么?

What's the best practice (or tool) for updating/migrating Mongoose schemas as the application evolves?

推荐答案

更新:经过测试,它不能以当前的形式运行,它的想法正确,我只需要一次迁移即可对模块本身进行了相当大的调整.但是,我认为如果不进行一些重大更改并以某种方式跟踪不同的模式,它就不会按预期工作.

Update: Tested, this does not work in its current form, its got the right idea going, I got a single migration to work with considerable tweaking of the module itself. But I don't see it working as intended without some major changes and keeping track of the different schemas somehow.

您想要猫鼬数据迁移之类的声音

Sounds like you want mongoose-data-migrations

它旨在在您使用文档时迁移旧的架构版本,这似乎是在mongodb中处理迁移的最佳方法.

It is intended to migrate old schema versions of your documents as you use them, which is seems to be the best way to handle migrations in mongodb.

您实际上并不想在文档集合(ala更改表)上运行完整的数据集迁移,因为这会给您的服务器带来沉重的负担,并且可能需要应用程序/服务器停机.有时您可能需要编写一个脚本,该脚本简单地抓取所有应用新模式/更改并调用保存的文档,但是您需要了解何时/何地执行此操作.一个例子可能是,将迁移逻辑添加到doc init中比将服务器停机3个小时来运行迁移脚本具有更大的性能损失.

You don't really want to run full dataset migrations on a document collection (ala alter table) as it puts a heavy load on your servers and could require application / server downtime. Sometimes you may need to write a script which simply grabs all documents applies the new schema / alterations and calls save, but you need to understand when/where to do that. An example might be, adding migration logic to doc init has more of a performance hit than taking down the server for 3 hours to run migration scripts is worth.

我发现此链接也非常有帮助,基本上更详细地重申了上述内容并基本上在php中实现了上述节点包的概念.

I found this link pretty helpful as well, basically reiterates the above in more detail and essentially implements the above node package's concept in php.

N.B.该模块已有5个月的历史,使用了0个分叉,但它环顾四周,无法找到比abdelsaid的响应方式更好/更有用的东西.

N.B. The module is 5months old, 0 forks, but am looking around and can't find anything better / more helpful than abdelsaid's style of response..

这篇关于处理猫鼬中的架构更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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