mongoDB Rename embedded field
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**
}
}
With mongoDB syntax, it would be something like
db.Users.update({}, {$rename:{"Orders.Name":"Orders.Something"}},true, true)
Thanks.
Look at
MongoDB.Driver.Builders.Update.Rename(string oldElementName,
string newElementName)
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.
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);
or
Query.GT("filesize", 200000).In(bsonArray);
精彩评论