State persistence stores program data so it remains available after a program stops. A customer or invoice object exists in memory during execution; persisting it lets a later run retrieve and work with its state. section 1.1
MongoDB stores data as documents, reducing the transformation needed to persist object-like structures. Documents can contain nested data and vary in their fields. That flexibility suits changing application data, while a relational database’s strict schema can provide stronger structural control for applications with precise transactional requirements. section 1.1 section 1.6
Listing 1.1 A MongoDB document with arrays and nested documents
{
"_id": 1,
"title": "MongoDB 8.0 in Action",
"publisher": "Manning Publications",
"status": "Available",
"focusAreas": [
"MongoDB Database System",
"Atlas Platform"
],
"publicationYear": 2025,
"additionalDetails": {
"embeddedDocument": {
"description": "A comprehensive guide to mastering
MongoDB 8.0, including working with the Atlas
Platform and learning the latest features"
}
}
}
This document shows how an object-like record can keep an array and nested details together in persistent storage. section 1.1
Two practical ways to use persistent documents are:
- Retrieve or change a stored record with MongoDB queries. For example, `db.books.find({ "title": "MongoDB 8.0 in Action" })` looks up a document by title; `updateOne` can change its publisher field. section 1.1
- Persist stream-processing results by reading events with `$source`, aggregating them within a `$tumblingWindow`, and writing the results to an Atlas collection with `$merge`. section 15.6.6
let m = {
$merge: {
into: {
connectionName: "mongodb-in-action-connection",
db: "spiDB",
coll: "spiColl"
}
}
}
The `$merge` stage names the Atlas connection, database, and collection that receive the processed results. section 15.6.6
Writing stream results to a collection preserves those results; it does not, by itself, establish how a stream processor’s internal state survives a failure. Choose what to store based on what the application must retrieve later. section 15.6.6 section 1.1






