MongoDB的重命名嵌入式领域 [英] mongoDB Rename embedded field

查看:195
本文介绍了MongoDB的重命名嵌入式领域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何使用C#与MongoDB的重命名嵌入式领域?文件的一个例子是:

how do we rename embedded fields using C# with mongoDB ? An example of document Person would be:

{
Id: 1,
LastName: "Smith",
FirstName: "John",
Orders: {
         Id: 1,
         Name: "Trousers" // I want to rename **Name** into **Something**
    }
}

使用MongoDB的语法,它会像

With mongoDB syntax, it would be something like

db.Users.update({}, {$rename:{"Orders.Name":"Orders.Something"}},true, true)

感谢

推荐答案

 MongoDB.Driver.Builders.Update.Rename(string oldElementName, 
                                       string newElementName)

它返回一个IUpdateQuery,这可以传递给collection.Update()和重命名你的领域。 C#的更新制造商有充分的特殊命令,您可以在蒙戈用作一个可调用函数来构建查询。

It returns an IUpdateQuery, which you can pass to collection.Update() and rename your field. The C# Update builder has every special command you can use in mongo as a callable function to build your query.

建筑工地命名空间是在MongoDB的C#的驱动程序有很大空间。它包括查询和更新建设者。你可以连续使用命令和做这样的事情:

The Builders namespace is a great namespace in the MongoDB C# driver. It includes Query and Update builders. You can chain commands and do things like this:

 Update.Set("indexsize", indexSize).Set("extractsize", extractedFileSize);

 Query.GT("filesize", 200000).In(bsonArray);

这篇关于MongoDB的重命名嵌入式领域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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