问题描述
只给一点背景的问题,我有一个Web应用程序(ASP MVC)基本上包装CRUD操作到MongoDB实例,它进行验证和某些业务逻辑之前的模型进行验证,并派人过来进行存储,检索等。
Just to give a little more context to the question, I have a web application (asp mvc) which basically wraps CRUD operations to a MongoDb instance, it carries out validation and certain business logic before the model is verified and sent over to be stored, retrieved etc.
现在有一个问题,我们有自己的是,在新版本的车型已经改变,但现有的数据还没有,这里有一个例子:(这是C#具体,但真正的问题是语言无关)
Now one problem we have his is that in the new version the models have changed but the existing data has not, here is an example: (it is c# specific but the question really is language agnostic)
public class Person
{
public Guid Id {get; set;}
public string Name {get; set;}
public int Age {get;set;}
public string BadgeNo {get;set;}
}
public class Person
{
public Guid Id {get; set;}
public string Name {get; set;}
public int Age {get;set;}
public string EmployeeNo {get; set;} // Still contains same data as BadgeNo just called something different
}
正如你所看到的物体的结构发生了变化,但在蒙戈土地它仍然传递出一个BadgeNo,而不是为employeeno。在SQL的土地,我们通常会拥有它运行的构建脚本这将改变架构和更新/插入/删除任何额外的数据,这些增量的一部分迁移脚本。
As you can see the structure of the objects have changed but in Mongo land it is still passing out a BadgeNo, not an EmployeeNo. In an SQL land we would usually have a migration script which is run as part of the build script which would change the schema and update/insert/delete any additional data for that delta.
那么它是如何最好地管理这些排序的迁移的与蒙戈?如果我也有,我用它来更新蒙戈在所有情况下的脚本?或者是有一些其他的preferred实践做这样的事情。
So how is it best to manage these sort of migrations with Mongo? Should I also have a script which I use to update all instances within Mongo? or is there some other preferred practise for doing this sort of thing.
关于这个问题的任何意见将是巨大的。
Any advice on the subject would be great
===编辑===
好像现在我想要去的迁移选项,而不是逐步淘汰的方式,所以考虑到这一点任何人都可以推荐任何工具,用于帮助在这一领域,否则每个迁移(假设辊式,转出)将必须是pre编译某种组合件与所有的逻辑。我在想的东西沿FluentMigrator的线条,但不是使用SQL工作,你正在使用蒙戈。目前使用南特我的生成脚本,我看到了一些红宝石的工具,但不知道是否有任何.NET等价。
It seems like currently I am wanting to go with the migration option rather than a phasing out approach, so with this in mind can anyone recommend any tools for helping in this area, as otherwise each migration (assuming a roll-in, roll-out) would have to be a pre compiled assembly of some kind with all the logic in. I was thinking something along the lines of FluentMigrator but instead of working with SQL you are working with Mongo. Currently my build scripts are using Nant, I have seen some ruby tools but not sure if there are any .net equivalent.
推荐答案
基本上有两种方法:
- 确保您的应用程序code可以处理版本的数据结构,并保存时,更新到新的结构
- 在写迁移脚本
我可能会去选择1,因为它的方法,使您可以逐步更新,其中与选项2,你基本上需要,以降低您的应用程序,让您可以更新code(快)和数据(可能慢)一气呵成。
I would probably go for option 1 as it's the method that allows you to gradually update, where as with option 2 you basically need to take down your application so that you can update the code (fast) and data (possibly slower) in one go.
后来的后来,或者如果你觉得有必要做的选件2以及过度迁移数据。这就不必记下你的网站,并能愉快地异步在后台运行。
Then later, or if you find it necessary do option 2 as well to migrate your data over. This then doesn't have to take down your site, and can happily run asynchronously in the background.
这篇关于处理与迁移的MongoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!