MongoDB

RetrieveMultiple

9 samples, from the least code that works to complete workflows.

What a RetrieveMultiple does

Rule On MongoDB
A query One aggregation pipeline: $match, $lookup for links, $group for aggregates, $sort, the page
Aggregates Count is a long on every provider. Sum and Avg read back in the database's own type (the Retrieve page's Aggregates table): code that runs on several providers reads them with Convert.ToDecimal(row["total"]).
Distinct query.Distinct = true returns rows that differ in no selected column once. The id isn't added to a distinct (or aggregate) query, since it would make every row distinct, so its rows have no RecordId: select the id column if you need it
Conditions Equality, comparisons, In, Between, patterns (escaped regular expressions; Contains, BeginsWith and EndsWith ignore case)
Field paths A dotted name in a condition, an order or a column set is a link's field when its first part is the link's alias (acc.name), and otherwise a path into an embedded document (address.city), each part checked by the name rules. The SQL providers refuse a dotted name that names no link (ARX1001)
Null Null matches a stored null and a missing field; NotEqual and the other negations never match either
Joins Inner and left ($lookup); a right join is ARX8001; link fields come back as alias.field
Paging By page number (with the total in the same round trip), or by the paging cookie each page returns
Paging cookies Sealed by default (encrypted and authenticated: a client can neither read nor change one), with a random key of the process unless PagingCookieKey is set. Several instances, or cookies across a restart: the same PagingCookieKey everywhere, or a cookie is ARX1001 on the other. PagingCookieProtection can be Signed or Plain (Advanced 4)

The samples

Basics

The least code that works.

1Read many recordsProgressive

Read many documents with conditions and an order, in three scenarios: comparisons and an order, text patterns, and what null means on MongoDB.

2Page through resultsProgressive

Page through a result, in two scenarios: by page number with the total, and by the paging cookie each page returns.

Real cases

What an application does: a small CRM and product catalogue.

1Read an account with its contactsProgressive

An account and its contacts, three ways: lookups read back as references with the account's name, a join ($lookup) from contacts to their account, and a left join that keeps contacts without one.

2A report by industryProgressive

A report from aggregates ($group), in two scenarios: counts and sums by industry, and the distinct regions.

3Catch an injection attemptProgressive

A search endpoint attacked three ways: an operator as the field to search, a regular expression as the text to find, and a sort field built from user input.

Advanced cases

Dependency injection, transactions, batch scopes and setting the service up.

1Read your writes in a transactionAdvanced

Reads inside an ARX transaction see its own writes; reads outside don't until the commit. Two scenarios: before and after the commit.

2A security check around a search endpointAdvanced

A security check around a search endpoint (SecurityGuard, in the project root), in four scenarios: a normal search passes; a sort field carrying SQL is logged and blocked after three strikes; a field list checked first keeps unknown names away from ARX; and a false positive (a column label with parentheses) is triaged and mapped, without blocking anyone.

3Set up the service from the database's schemaAdvanced

The service set up from the database instead of by hand, then reading through it, in two scenarios: preload the lead collection at startup, and reading with Strict on, where only the preloaded fields may be named.

4Protect paging cookiesAdvanced

Protect the paging cookies your API hands to clients, in three scenarios: sealed by default, one key shared by every instance of the application, and plain cookies when you choose them.