MongoDB · Types · Services and connections
ArxMongoDbService
Definition
- Namespace
ARX.SDK.MongoDb.Services- Package
ARX.SDK.MongoDb
public class ArxMongoDbServiceThe MongoDB service: Create, Update, Delete, Retrieve and RetrieveMultiple against one database, a collection per entity. Give it the connection string (naming the database: mongodb://…/crm) and, usually, the application's schema catalog. It shares one MongoClient per connection string (the driver's advice: a client is a pool, made once), so one instance serves the whole application.
Constructor
ArxMongoDbService(string connectionString)A service for the database the connection string names, with no schema catalog.
Parameter Type Description connectionStringstringA MongoDB connection string naming the database: mongodb://user:password@host:27017/crm?authSource=admin.ArxMongoDbService(string connectionString, ArxSchemaCatalog schema)A service with the application's schema catalog: the usual way.
Parameter Type Description connectionStringstringA MongoDB connection string naming the database. schemaArxSchemaCatalogThe developer's schema catalog: every collection's id column (the document's _id) and keys, lookups, display names, and the selection sets thatArxSelectionSetValueattributes are checked against. ARX never reads it from the database by itself.ArxMongoDbService(string connectionString, string database, ArxSchemaCatalog schema)A service for
database, which overrides the database the connection string names.Parameter Type Description connectionStringstringA MongoDB connection string. databasestringThe database; null for the one the connection string names. schemaArxSchemaCatalogThe developer's schema catalog; null for none. ArxMongoDbService(IMongoClient client, string database, ArxSchemaCatalog? schema = null)A service on a client the application made and owns (dependency injection: register the
IMongoClientas a singleton, as the driver advises).Parameter Type Description clientIMongoClientThe client; ARX never disposes it. databasestringThe database. schemaArxSchemaCatalog?= nullThe developer's schema catalog; null for none.
Properties
string? ConnectionString { get; }The connection string; null when the service was given a client.
string DatabaseName { get; }The database every call reads and writes.
ArxSchemaCatalog Schema { get; }The developer's schema catalog; null when none was supplied.
IArxSelectionSetCatalog SelectionSetCatalog { get; }The catalog
ArxSelectionSetValueattributes are checked against; null when none was supplied.IArxProviderCapabilities Capabilities { get; }What MongoDB supports through ARX: joins (
$lookup, inner and left), aggregates ($group), paging by page number with the total and by cookie, transactions and the multiple-document writes (on a replica set or sharded cluster), full-text search ($text), pattern conditions and Or filters. Not Execute (MongoDB has no stored procedures: ARX8001), not upsert, not named indexes.byte[] PagingCookieKey { get; set; }The key of the paging cookies (
PagingCookie): 32 bytes or more. Null (the default) uses a random key of the process's own (every service in it shares it), which is right for one process. An application that runs several instances behind one address, or keeps cookies across a restart, sets the same key on every instance (from its configuration or secret store): otherwise a cookie that reaches another instance is ARX1001. Set it before the first call.ArxPagingCookieProtection PagingCookieProtection { get; set; }How paging cookies are protected:
Sealedby default (a client can neither read nor change a cookie, which carries the last item's key values),Signed(readable, not changeable) orPlain. Set it before the first call; every instance needs the same.bool Strict { get; set; }False (the default): a preloaded schema is what ARX knows ahead of time; collections and fields it doesn't list still work. True: the preloaded fields are an allow list, and a call that names a collection or a field the schema doesn't preload is refused before the database with ARX1018 NotPreloaded. Reading every field reads what the documents hold, as without Strict.
Methods
Task<IArxBatchScope> BeginBatchAsync(ArxBatchOptions? options = null, CancellationToken cancellationToken = default)Opens a batch scope: one MongoDB transaction across many calls, committed by
CommitAsync; disposing it without a commit rolls it back. MongoDB has no savepoints, so a failed call rolls the whole scope back; asking for savepoints (Savepoints = true) is ARX8001. Needs a replica set or a sharded cluster.Parameter Type Description optionsArxBatchOptions?= nullThe scope's options; null for the defaults (no savepoints). cancellationTokenCancellationToken= defaultCancels the call. Task<ArxTransaction> BeginTransactionAsync(CancellationToken cancellationToken = default)Begins a transaction on a connection of its own (a new
ArxMongoConnection), for code that works throughIArxDataServiceand so can't name the provider's connection type. Pass it to the calls, then commit it; disposing it without committing rolls it back, and closes its connection:await using var transaction = await service.BeginTransactionAsync();Parameter Type Description cancellationTokenCancellationToken= defaultCancels the call. Task<ArxExecuteResult> ExecuteAsync(ArxProcedureExpression procedure, ArxExecuteOptions? options = null, CancellationToken cancellationToken = default)Not offered: MongoDB has no stored procedures or functions that return rows. Always ARX8001; read with RetrieveMultiple (aggregates and joins included), and keep server-side logic in the application.
Parameter Type Description procedureArxProcedureExpressionThe procedure or function to call, with its arguments. optionsArxExecuteOptions?= nullOptions of the call (paging, command timeout); null for the defaults. cancellationTokenCancellationToken= defaultCancels the call. Task<ArxExecuteResult> ExecuteAsync(ArxProcedureExpression procedure, ArxTransaction transaction, ArxExecuteOptions? options = null, CancellationToken cancellationToken = default)As
ExecuteAsync: always ARX8001.Parameter Type Description procedureArxProcedureExpressionThe procedure or function to call, with its arguments. transactionArxTransactionThe ARX transaction to run in (from the provider's connection type). ARX doesn't commit or roll it back. optionsArxExecuteOptions?= nullOptions of the call (paging, command timeout); null for the defaults. cancellationTokenCancellationToken= defaultCancels the call. Task<ArxRecordId> CreateAsync(ArxEntity entity, CancellationToken cancellationToken = default)Inserts one document and returns its id, also set on
RecordId.Parameter Type Description entityArxEntityThe record to create: its table and the attributes to write. Its RecordIdis set to the new id.cancellationTokenCancellationToken= defaultCancels the call. Task<ArxRecordId> CreateAsync(ArxEntity entity, ArxTransaction transaction, CancellationToken cancellationToken = default)Inserts one document in an ARX transaction (
ArxMongoConnection), asCreateAsync.Parameter Type Description entityArxEntityThe record to create: its table and the attributes to write. Its RecordIdis set to the new id.transactionArxTransactionThe ARX transaction to run in (from the provider's connection type). ARX doesn't commit or roll it back. cancellationTokenCancellationToken= defaultCancels the call. Task<IReadOnlyList<ArxRecordId>> CreateMultipleAsync(IReadOnlyList<ArxEntity> entities, CancellationToken cancellationToken = default)Inserts every entity, all or nothing, and returns one id per entity in list order, also set on each entity's RecordId. The documents go in ordered
insertManybatches inside a transaction of ARX's own, which needs a replica set: on a standalone server more than one entity is ARX8001 (seeAllowPartial). The same entity twice is ARX1001. An empty list returns no ids without touching the database.Parameter Type Description entitiesIReadOnlyList<ArxEntity>The records to create, all or nothing; their ids come back in the same order. cancellationTokenCancellationToken= defaultCancels the call. Task<IReadOnlyList<ArxRecordId>> CreateMultipleAsync(IReadOnlyList<ArxEntity> entities, ArxMongoWriteOptions options, CancellationToken cancellationToken = default)As
CreateMultipleAsync, with write options.Parameter Type Description entitiesIReadOnlyList<ArxEntity>The records to create, all or nothing; their ids come back in the same order. optionsArxMongoWriteOptionsOptions of the write: AllowPartiallets a standalone server (which has no transactions) write the documents in order, without all or nothing.cancellationTokenCancellationToken= defaultCancels the call. Task<IReadOnlyList<ArxRecordId>> CreateMultipleAsync(IReadOnlyList<ArxEntity> entities, ArxTransaction transaction, CancellationToken cancellationToken = default)As
CreateMultipleAsync, in an ARX transaction.Parameter Type Description entitiesIReadOnlyList<ArxEntity>The records to create, all or nothing; their ids come back in the same order. transactionArxTransactionThe ARX transaction to run in (from the provider's connection type). ARX doesn't commit or roll it back. cancellationTokenCancellationToken= defaultCancels the call. Task<IReadOnlyList<ArxRecordId>> CreateMultipleAsync(IReadOnlyList<ArxEntity> entities, ArxSchemaCatalog schema, CancellationToken cancellationToken = default)As
CreateMultipleAsync, with the tables declared for this call:schemaoverrides the service's schema per table (selection sets by name).Parameter Type Description entitiesIReadOnlyList<ArxEntity>The records to create, all or nothing; their ids come back in the same order. schemaArxSchemaCatalogDeclarations for this call only: they replace the service's for the tables they declare. cancellationTokenCancellationToken= defaultCancels the call. Task<IReadOnlyList<ArxRecordId>> CreateMultipleAsync(IReadOnlyList<ArxEntity> entities, ArxSchemaCatalog schema, ArxTransaction transaction, CancellationToken cancellationToken = default)The call-schema form in an ARX transaction.
Parameter Type Description entitiesIReadOnlyList<ArxEntity>The records to create, all or nothing; their ids come back in the same order. schemaArxSchemaCatalogDeclarations for this call only: they replace the service's for the tables they declare. transactionArxTransactionThe ARX transaction to run in (from the provider's connection type). ARX doesn't commit or roll it back. cancellationTokenCancellationToken= defaultCancels the call. Task<bool> DeleteAsync(string entityName, ArxRecordId id, CancellationToken cancellationToken = default)Deletes the document with this id (the one CreateAsync returned); true when one was deleted.
Parameter Type Description entityNamestringThe table to delete from. idArxRecordIdThe record's id: the value Create returned, or a plain value of the declared id's type. cancellationTokenCancellationToken= defaultCancels the call. Task<bool> DeleteAsync(string entityName, ArxRecordId id, ArxTransaction transaction, CancellationToken cancellationToken = default)Deletes by id in an ARX transaction.
Parameter Type Description entityNamestringThe table to delete from. idArxRecordIdThe record's id: the value Create returned, or a plain value of the declared id's type. transactionArxTransactionThe ARX transaction to run in (from the provider's connection type). ARX doesn't commit or roll it back. cancellationTokenCancellationToken= defaultCancels the call. Task<int> DeleteAsync(ArxEntity entity, ArxDeleteOptions? options = null, CancellationToken cancellationToken = default)Deletes the documents
entityidentifies (by id by default, orMatch) and returns how many went. None is a normal outcome (0), unlessRequireSingleRow: then none is ARX2002 and several ARX2003, and nothing is deleted.Parameter Type Description entityArxEntityThe record to delete: its table and the id, key or columns that find it. optionsArxDeleteOptions?= nullHow the rows are found ( Match) and checked; null for the defaults (by id).cancellationTokenCancellationToken= defaultCancels the call. Task<int> DeleteAsync(ArxEntity entity, ArxTransaction transaction, ArxDeleteOptions? options = null, CancellationToken cancellationToken = default)As
DeleteAsync, in an ARX transaction.Parameter Type Description entityArxEntityThe record to delete: its table and the id, key or columns that find it. transactionArxTransactionThe ARX transaction to run in (from the provider's connection type). ARX doesn't commit or roll it back. optionsArxDeleteOptions?= nullHow the rows are found ( Match) and checked; null for the defaults (by id).cancellationTokenCancellationToken= defaultCancels the call. Task<int> DeleteMultipleAsync<TId>(string entityName, IReadOnlyCollection<TId> ids, CancellationToken cancellationToken = default)Deletes the records with these ids, all or nothing, and returns how many existed. Ids that match nothing aren't an error: the count shows them. Duplicates count once. An empty list returns 0 without touching the database. One method for every id type (1.0.0-rc.1): a list of
long,int,Guid,stringorArxRecordId; another element type is ARX1007 UnsupportedValueType.Parameter Type Description entityNamestringThe table to delete from. idsIReadOnlyCollection<TId>The ids of the records to delete; ids that match nothing are left out of the count. cancellationTokenCancellationToken= defaultCancels the call. Task<int> DeleteMultipleAsync<TId>(string entityName, IReadOnlyCollection<TId> ids, ArxTransaction transaction, CancellationToken cancellationToken = default)Deletes the records with these ids, all or nothing, and returns how many existed, inside an ARX transaction. Ids that match nothing aren't an error: the count shows them. Duplicates count once. An empty list returns 0 without touching the database. One method for every id type (1.0.0-rc.1): a list of
long,int,Guid,stringorArxRecordId; another element type is ARX1007 UnsupportedValueType.Parameter Type Description entityNamestringThe table to delete from. idsIReadOnlyCollection<TId>The ids of the records to delete; ids that match nothing are left out of the count. transactionArxTransactionThe ARX transaction to run in. ARX doesn't commit or roll it back. cancellationTokenCancellationToken= defaultCancels the call. Task<int> DeleteMultipleAsync(IReadOnlyList<ArxEntity> entities, ArxDeleteOptions? options = null, CancellationToken cancellationToken = default)Deletes the documents the entities match and returns how many went, all or nothing (in a transaction of ARX's own on a replica set). By id: one
deleteManyper collection. With RequireSingleRow every entity must match exactly one (ARX2002, ARX2003, nothing deleted). The same entity or match values twice is ARX1001.Parameter Type Description entitiesIReadOnlyList<ArxEntity>The records to delete, all or nothing, each found by its id or by the match's columns. optionsArxDeleteOptions?= nullHow the rows are found ( Match) and checked; null for the defaults (by id).cancellationTokenCancellationToken= defaultCancels the call. Task<int> DeleteMultipleAsync(IReadOnlyList<ArxEntity> entities, ArxSchemaCatalog schema, ArxDeleteOptions? options = null, CancellationToken cancellationToken = default)With the tables declared for this call.
Parameter Type Description entitiesIReadOnlyList<ArxEntity>The records to delete, all or nothing, each found by its id or by the match's columns. schemaArxSchemaCatalogThe schema catalog: each table's id, keys, lookups and columns, and the selection sets. Null for none. optionsArxDeleteOptions?= nullHow the rows are found ( Match) and checked; null for the defaults (by id).cancellationTokenCancellationToken= defaultCancels the call. Task<int> DeleteMultipleAsync(IReadOnlyList<ArxEntity> entities, ArxTransaction transaction, ArxDeleteOptions? options = null, CancellationToken cancellationToken = default)In an ARX transaction.
Parameter Type Description entitiesIReadOnlyList<ArxEntity>The records to delete, all or nothing, each found by its id or by the match's columns. transactionArxTransactionThe ARX transaction to run in (from the provider's connection type). ARX doesn't commit or roll it back. optionsArxDeleteOptions?= nullHow the rows are found ( Match) and checked; null for the defaults (by id).cancellationTokenCancellationToken= defaultCancels the call. Task<int> DeleteMultipleAsync(IReadOnlyList<ArxEntity> entities, ArxSchemaCatalog schema, ArxTransaction transaction, ArxDeleteOptions? options = null, CancellationToken cancellationToken = default)The call-schema form in an ARX transaction.
Parameter Type Description entitiesIReadOnlyList<ArxEntity>The records to delete, all or nothing, each found by its id or by the match's columns. schemaArxSchemaCatalogThe schema catalog: each table's id, keys, lookups and columns, and the selection sets. Null for none. transactionArxTransactionThe ARX transaction to run in (from the provider's connection type). ARX doesn't commit or roll it back. optionsArxDeleteOptions?= nullHow the rows are found ( Match) and checked; null for the defaults (by id).cancellationTokenCancellationToken= defaultCancels the call. Task<int> UpdateMultipleAsync(ArxEntity values, ArxFilterExpression filter, ArxFilterWriteOptions? options = null, CancellationToken cancellationToken = default)Sets
values' attributes on every document of its collection thatfiltermatches, in oneupdateManywith$set, and returns how many matched.Parameter Type Description valuesArxEntityThe collection (EntityName) and the attributes to set: null stores null. filterArxFilterExpressionThe documents to change: conditions on the collection's own fields. optionsArxFilterWriteOptions?= nullAllRows for an empty filter; null for the defaults. cancellationTokenCancellationToken= defaultCancels the call. Task<int> UpdateMultipleAsync(ArxEntity values, ArxFilterExpression filter, ArxTransaction transaction, ArxFilterWriteOptions? options = null, CancellationToken cancellationToken = default)The update by a filter inside an ARX transaction. A database error aborts the transaction.
Parameter Type Description valuesArxEntityThe collection (EntityName) and the attributes to set: null stores null. filterArxFilterExpressionThe documents to change: conditions on the collection's own fields. transactionArxTransactionThe ARX transaction to run in (from the provider's connection type). ARX doesn't commit or roll it back. optionsArxFilterWriteOptions?= nullAllRows for an empty filter; null for the defaults. cancellationTokenCancellationToken= defaultCancels the call. Task<int> DeleteMultipleAsync(string entityName, ArxFilterExpression filter, ArxFilterWriteOptions? options = null, CancellationToken cancellationToken = default)Deletes every document of the collection that
filtermatches, in onedeleteMany, and returns how many went. The filter's rules are the update's: the collection's own fields, and an empty filter is ARX1001 unlessAllRowsis set.Parameter Type Description entityNamestringThe collection to delete from. filterArxFilterExpressionThe documents to delete: conditions on the collection's own fields. optionsArxFilterWriteOptions?= nullAllRows for an empty filter; null for the defaults. cancellationTokenCancellationToken= defaultCancels the call. Task<int> DeleteMultipleAsync(string entityName, ArxFilterExpression filter, ArxTransaction transaction, ArxFilterWriteOptions? options = null, CancellationToken cancellationToken = default)The delete by a filter inside an ARX transaction. A database error aborts the transaction.
Parameter Type Description entityNamestringThe collection to delete from. filterArxFilterExpressionThe documents to delete: conditions on the collection's own fields. transactionArxTransactionThe ARX transaction to run in (from the provider's connection type). ARX doesn't commit or roll it back. optionsArxFilterWriteOptions?= nullAllRows for an empty filter; null for the defaults. cancellationTokenCancellationToken= defaultCancels the call. Task<IReadOnlyList<ArxRecordId>> CreateMultipleAsync(IReadOnlyList<ArxEntity> entities, ArxCreateMultipleOptions options, CancellationToken cancellationToken = default)Creates the documents, all or nothing. MongoDB's ids are ARX's to make (or supplied), so the call is the same
insertManyasCreateMultipleAsync; withReturnIdsfalse every id returned isNone.Parameter Type Description entitiesIReadOnlyList<ArxEntity>The records to create, all or nothing. optionsArxCreateMultipleOptionsReturnIds false when the ids aren't needed. cancellationTokenCancellationToken= defaultCancels the call. Task<IReadOnlyList<ArxRecordId>> CreateMultipleAsync(IReadOnlyList<ArxEntity> entities, ArxCreateMultipleOptions options, ArxTransaction transaction, CancellationToken cancellationToken = default)CreateMultiple with options inside an ARX transaction. A database error aborts the transaction.
Parameter Type Description entitiesIReadOnlyList<ArxEntity>The records to create, all or nothing. optionsArxCreateMultipleOptionsReturnIds false when the ids aren't needed. transactionArxTransactionThe ARX transaction to run in (from the provider's connection type). ARX doesn't commit or roll it back. cancellationTokenCancellationToken= defaultCancels the call. Task<ArxEntity?> RetrieveAsync(string entityName, ArxRecordId id, ArxColumnSet? columns = null, CancellationToken cancellationToken = default)The document with this id (the one CreateAsync returned), or null.
Parameter Type Description entityNamestringThe table or view to read. idArxRecordIdThe record's id: the value Create returned, or a plain value of the declared id's type. columnsArxColumnSet?= nullThe columns to read; null or an empty set reads every column. The declared id is always read. cancellationTokenCancellationToken= defaultCancels the call. Task<ArxEntity?> RetrieveAsync(string entityName, ArxRecordId id, ArxTransaction transaction, ArxColumnSet? columns = null, CancellationToken cancellationToken = default)By id in an ARX transaction.
Parameter Type Description entityNamestringThe table or view to read. idArxRecordIdThe record's id: the value Create returned, or a plain value of the declared id's type. transactionArxTransactionThe ARX transaction to run in (from the provider's connection type). ARX doesn't commit or roll it back. columnsArxColumnSet?= nullThe columns to read; null or an empty set reads every column. The declared id is always read. cancellationTokenCancellationToken= defaultCancels the call. Task<ArxEntity?> RetrieveAsync(ArxEntity match, ArxRetrieveOptions? options = null, CancellationToken cancellationToken = default)The one document
matchidentifies: by its id by default, or by a declared key or any fields (Match). Null when none matches; ARX2003 when several do (a Retrieve answers one record).Parameter Type Description matchArxEntityThe record to find: its table, and the values of the id, the declared key or the columns that find it. optionsArxRetrieveOptions?= nullHow the row is found and read (match, command timeout, lookup names); null for the defaults. cancellationTokenCancellationToken= defaultCancels the call. Task<ArxEntity?> RetrieveAsync(ArxEntity match, ArxTransaction transaction, ArxRetrieveOptions? options = null, CancellationToken cancellationToken = default)As
RetrieveAsync, in an ARX transaction.Parameter Type Description matchArxEntityThe record to find: its table, and the values of the id, the declared key or the columns that find it. transactionArxTransactionThe ARX transaction to run in (from the provider's connection type). ARX doesn't commit or roll it back. optionsArxRetrieveOptions?= nullHow the row is found and read (match, command timeout, lookup names); null for the defaults. cancellationTokenCancellationToken= defaultCancels the call. Task<ArxEntityCollection> RetrieveMultipleAsync(ArxQueryExpression query, ArxRetrieveOptions? options = null, CancellationToken cancellationToken = default)Runs a query as one aggregation pipeline and returns its documents: filters (equality, comparisons, In, Between, null checks where null also means a missing field, patterns as escaped regular expressions), joins as
$lookup(inner and left), aggregates as$group, order on any fields, and paging by page number (with the total in the same round trip,$facet) or by the paging cookie each page returns (a keyset on the order and the id: no documents skipped on the server).Parameter Type Description queryArxQueryExpressionThe query: its row source, columns, criteria, links, order, paging and aggregates. optionsArxRetrieveOptions?= nullHow the row is found and read (match, command timeout, lookup names); null for the defaults. cancellationTokenCancellationToken= defaultCancels the call. Task<ArxEntityCollection> RetrieveMultipleAsync(ArxQueryExpression query, ArxTransaction transaction, ArxRetrieveOptions? options = null, CancellationToken cancellationToken = default)As
RetrieveMultipleAsync, in an ARX transaction.Parameter Type Description queryArxQueryExpressionThe query: its row source, columns, criteria, links, order, paging and aggregates. transactionArxTransactionThe ARX transaction to run in (from the provider's connection type). ARX doesn't commit or roll it back. optionsArxRetrieveOptions?= nullHow the row is found and read (match, command timeout, lookup names); null for the defaults. cancellationTokenCancellationToken= defaultCancels the call. Task ValidateSchemaAsync(CancellationToken cancellationToken = default)Compares every collection in the schema catalog with the database: the collection exists (MongoDB makes one on the first insert, so a missing one also means its indexes are missing); a stored document's
_idhas the declared id's type (an ObjectId for a generated string id); and every declared key has a unique index on exactly its fields. ARX never calls this by itself: run it at startup or in a health check. It reads only, and reports every difference at once (ARX5003 SchemaMismatch).Parameter Type Description cancellationTokenCancellationToken= defaultCancels the call. Task<ArxServerCheck> CheckServerAsync(CancellationToken cancellationToken = default)What the connected server allows: its version, and the provider's capabilities on it. A standalone server runs no transactions, so it removes
TransactionsandBulkWrite(writes of several documents, all or nothing); a replica set or a sharded cluster has both. Call it once at startup.Parameter Type Description cancellationTokenCancellationToken= defaultCancels the call. Task<int> UpdateAsync(ArxEntity entity, ArxUpdateOptions? options = null, CancellationToken cancellationToken = default)Updates the documents
entityidentifies and returns how many matched.Parameter Type Description entityArxEntityThe change: its table, the attributes to write (null clears a column; an attribute left out keeps its value), and the id, key or columns that find the row. optionsArxUpdateOptions?= nullHow the rows are found ( Match) and checked; null for the defaults (by id).cancellationTokenCancellationToken= defaultCancels the call. Task<int> UpdateAsync(ArxEntity entity, ArxTransaction transaction, ArxUpdateOptions? options = null, CancellationToken cancellationToken = default)As
UpdateAsync, in an ARX transaction.Parameter Type Description entityArxEntityThe change: its table, the attributes to write (null clears a column; an attribute left out keeps its value), and the id, key or columns that find the row. transactionArxTransactionThe ARX transaction to run in (from the provider's connection type). ARX doesn't commit or roll it back. optionsArxUpdateOptions?= nullHow the rows are found ( Match) and checked; null for the defaults (by id).cancellationTokenCancellationToken= defaultCancels the call. Task<int> UpdateMultipleAsync(IReadOnlyList<ArxEntity> entities, ArxUpdateOptions? options = null, CancellationToken cancellationToken = default)Updates every entity, all or nothing, and returns the documents matched. If any entity matches no document, nothing changes and the call throws ARX2002 with how many were missing. The same entity twice, or the same match values twice, is ARX1001. Matches by id go in one ordered
bulkWriteper collection; matches by a key or fields oneupdateManyeach, so each entity's count is known. All in a transaction of ARX's own (a replica set: on a standalone server ARX8001). An empty list returns 0 without touching the database.Parameter Type Description entitiesIReadOnlyList<ArxEntity>The changes, all or nothing: each carries the attributes to write and what finds its row. optionsArxUpdateOptions?= nullHow the rows are found ( Match) and checked; null for the defaults (by id).cancellationTokenCancellationToken= defaultCancels the call. Task<int> UpdateMultipleAsync(IReadOnlyList<ArxEntity> entities, ArxSchemaCatalog schema, ArxUpdateOptions? options = null, CancellationToken cancellationToken = default)As
UpdateMultipleAsync, with the tables declared for this call.Parameter Type Description entitiesIReadOnlyList<ArxEntity>The changes, all or nothing: each carries the attributes to write and what finds its row. schemaArxSchemaCatalogThe schema catalog: each table's id, keys, lookups and columns, and the selection sets. Null for none. optionsArxUpdateOptions?= nullHow the rows are found ( Match) and checked; null for the defaults (by id).cancellationTokenCancellationToken= defaultCancels the call. Task<int> UpdateMultipleAsync(IReadOnlyList<ArxEntity> entities, ArxTransaction transaction, ArxUpdateOptions? options = null, CancellationToken cancellationToken = default)As
UpdateMultipleAsync, in an ARX transaction.Parameter Type Description entitiesIReadOnlyList<ArxEntity>The changes, all or nothing: each carries the attributes to write and what finds its row. transactionArxTransactionThe ARX transaction to run in (from the provider's connection type). ARX doesn't commit or roll it back. optionsArxUpdateOptions?= nullHow the rows are found ( Match) and checked; null for the defaults (by id).cancellationTokenCancellationToken= defaultCancels the call. Task<int> UpdateMultipleAsync(IReadOnlyList<ArxEntity> entities, ArxSchemaCatalog schema, ArxTransaction transaction, ArxUpdateOptions? options = null, CancellationToken cancellationToken = default)The call-schema form in an ARX transaction.
Parameter Type Description entitiesIReadOnlyList<ArxEntity>The changes, all or nothing: each carries the attributes to write and what finds its row. schemaArxSchemaCatalogThe schema catalog: each table's id, keys, lookups and columns, and the selection sets. Null for none. transactionArxTransactionThe ARX transaction to run in (from the provider's connection type). ARX doesn't commit or roll it back. optionsArxUpdateOptions?= nullHow the rows are found ( Match) and checked; null for the defaults (by id).cancellationTokenCancellationToken= defaultCancels the call.
Usage
A line from a verified sample; the full, runnable code is on its page.
var service = new ArxMongoDbService(connectionString, schema);Create one record and get its id, scenario 1
Used in:
- Create one record and get its idCreate
- Create a record that refers to anotherCreate
- Catch the errors a create meetsCreate
- Store every kind of valueCreate
- Catch an injection attemptCreate
- Create in an ARX transactionCreate
- Set up the service from the database's schemaCreate
- Use fields named outside the name rule, through aliasesCreate
- Create many records in one callCreateMultiple
- Update one recordUpdate
- Choose how the documents are foundUpdate
- Catch an injection attemptUpdate
- Update in a batch scopeUpdate
- Set up the service from the database's schemaUpdate
- Update many records in one callUpdateMultiple
- Update or delete every document a filter matchesUpdateMultiple
- Delete one record by idDelete
- Choose how the documents are foundDelete
- Catch an injection attemptDelete
- Replace a record in a transactionDelete
- Set up the service from the database's schemaDelete
- Delete many records in one callDeleteMultiple
- Read one recordRetrieve
- Read many recordsRetrieveMultiple
- Page through resultsRetrieveMultiple
- Read an account with its contactsRetrieveMultiple
- A report by industryRetrieveMultiple
- Catch an injection attemptRetrieveMultiple
- Read your writes in a transactionRetrieveMultiple
- Set up the service from the database's schemaRetrieveMultiple
- Protect paging cookiesRetrieveMultiple
- The sample application
Notes
The table's declared id column is the document's _id; the entity names it by the declared column (entity["account_id"]). Field names keep their case (MongoDB compares them exactly). Writes of several documents run in a transaction, which needs a replica set or a sharded cluster: on a standalone server they are refused (ARX8001) rather than half done.