管理类结构的更改以与 mongodb 集合保持一致
我们正在使用 mongodb 和 c#。我们正在努力寻找一种方法来保持我们的系列无缝一致。现在,如果开发人员对类结构进行任何更改(添加字段或更改数据类型或更改嵌套类中的属性),他/她必须手动更改 mongo 集合。
随着我们的项目不断发展,并且从事该项目的开发人员不断增加,这很痛苦。想知道是否有人已经找到了解决此问题的方法。
We are using mongodb with c#. We are trying to figure out a way to keep our collection consistent seamlessly. Right now, if a developer make any changes to the class structure(add a field or change data type or changing the property within a nested class) he/she has to change the mongo collection manually.
Its a pain as our project is growing and the developers working on the project keeps increasing. Was wondering whether someone already have figured out a way to manage this issue.
- Research
- I found a similar question. however, couldn't find the solution.
- Found a way to find all properties Finding the properties; however, datatype and nested documents becomes an issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望在访问记录时逐渐迁移,则需要遵循一些简单的规则:
1) 如果添加字段,则该字段最好可以为空或指定默认值。
2) 永远不要重命名字段,永远不要更改字段类型
- 相反,总是添加新字段,添加迁移代码,仅当所有文档都已迁移完毕时才删除旧字段。
为了使用 MongoDB 和 C# 进行原型设计,我构建了一个 动态包装 ...它允许您仅使用 来指定对象 接口(不需要类),并且它允许您动态地将新接口添加到现有对象。尚未准备好用于生产使用,但对于原型设计而言,它可以节省大量精力并使迁移变得非常容易。
If you want to migrate gradually as records are accessed you need to follow a few simple rules:
1) If you add a field it had better be nullable or have a default value specified.
2) Never rename fields, never change field types
- Instead always add new fields, add migration code, remove the old fields only when all documents have been migrated over.
For prototyping with MongoDB and C# I build a dynamic wrapper ... that lets you specify your objects using only interfaces (no classes needed), and it lets you dynamically add new interfaces to an existing object. Not ready for production use but for prototyping it saves a lot of effort and makes migration really easy.