Skip to content

Composite attribute support - #2

Merged
colemancda merged 6 commits into
masterfrom
feature/composite-attribute
Aug 16, 2026
Merged

Composite attribute support#2
colemancda merged 6 commits into
masterfrom
feature/composite-attribute

Conversation

@colemancda

Copy link
Copy Markdown
Member

Adds composite attribute support, following CoreModel #11. Requires CoreModel 2.11.0.

Storage

A composite maps onto MongoDB's embedded document — its native shape for structured values, so no flattening or serialization is needed:

{ "location": { "latitude": 40.7, "longitude": -74.0 } }

Element key paths are the dotted paths the server already understands, so location.latitude > 30 becomes an ordinary query with no rewriting:

{ "location.latitude": { "$gt": 30 } }

Decoding iterates the declared elements rather than the stored document, so a stale field the schema no longer declares is ignored rather than mis-typed, and an element missing from the document decodes as .null so the decoded shape always matches the schema.

The in-memory evaluation fallback (used for predicates the server can't run, e.g. custom functions) also descends into composite elements.

Also included

.arithmetic expressions (new in CoreModel 2.11.0) are rejected for server-side queries and return nil from the in-memory fallback rather than being silently mis-evaluated; both marked TODO. containsFunction does recurse into arithmetic operands, since an operand can contain a function call.

Testing

12 tests covering BSON encode/decode, nested composites, missing and unknown elements, wrong element types, null handling, key-path resolution (including the empty-key-path edge case), and the generated server queries for flat and nested element paths. All pass.

Caveat: these are server-free unit tests. The composite logic lives in the conversion and key-path code they cover, but the end-to-end query path has not been exercised against a live mongod — no local instance was available. Worth an integration run before merging.

@colemancda
colemancda merged commit 0177603 into master Aug 16, 2026
1 check passed
@colemancda
colemancda deleted the feature/composite-attribute branch August 16, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant