MongoDB Rename Inline Field

how to rename inline fields using c # using mongoDB? An example of a Person document would be:

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

With mongoDB syntax, it will be something like

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

Thanks.

+4
source share
1 answer

Take a look

  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 constructor has every special command that you can use in mongo as a function call to create a request.

The Builders namespace is a great namespace in the C # MongoDB driver. It includes query and update collectors. You can hook on teams and do things like this:

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

or

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

All Articles