FireDAC.Phys.MongoDBWrapper.TMongoCollection.Update

From Appmethod Libraries
Jump to: navigation, search

Object Pascal

procedure Update(AUpdate: TMongoUpdate; AFlags: TUpdateFlags = [TUpdateFlag.MultiUpdate]); overload;
function Update(AFlags: TUpdateFlags = [TUpdateFlag.MultiUpdate]): TMongoUpdate; overload;

C++

void __fastcall Update(TMongoUpdate* AUpdate, TUpdateFlags AFlags = (TUpdateFlags() << TUpdateFlag::MultiUpdate ))/* overload */;
TMongoUpdate* __fastcall Update(TUpdateFlags AFlags = (TUpdateFlags() << TUpdateFlag::MultiUpdate ))/* overload */;

Properties

Type Visibility Source Unit Parent
procedure
function
public
FireDAC.Phys.MongoDBWrapper.pas
FireDAC.Phys.MongoDBWrapper.hpp
FireDAC.Phys.MongoDBWrapper TMongoCollection

Description

Executes the specified update builder on the collection.

Update supports two different coding styles.

You can optionally specify a set of update flags.

If the update operation succeeds, you can obtain the number of updated documents from the DocsModified and DocsUpserted properties.
If the update operation fails, it raises an exception.

Example

The following example changes the cuisine of Italian restaurants to "Mediterranean".

MongDB shell:

db.restaurants.update(
    { cuisine: "Italian" },
    { $set: { cuisine: "Mediterranean" } },
    { multi: true }
  )

Object Pascal:

MyCollection.Update
  .Match
    .Add('cuisine', 'Italian')
    .&End
  .Modify
    .&Set
      .Field('cuisine', 'Mediterranean')
    .&End
  .&End
  .Exec;

C++:

MyCollection->Update()
  ->Match()
    ->Add("cuisine", "Italian")
    ->End()
  ->Modify()
    ->Set()
      ->Field("cuisine", "Mediterranean")
    ->End()
  ->End()
  ->Exec();

See Also