[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-18。"],[],[],null,["# Behavior differences\n====================\n\nThis page describes behavioral differences between Firestore with MongoDB compatibility and MongoDB.\n\nFor a breakdown of supported features depending on MongoDB version, see:\n\n- [Supported features: 8.0](/firestore/mongodb-compatibility/docs/supported-features-80)\n- [Supported features: 7.0](/firestore/mongodb-compatibility/docs/supported-features-70)\n- [Supported features: 6.0](/firestore/mongodb-compatibility/docs/supported-features-60)\n- [Supported features: 5.0](/firestore/mongodb-compatibility/docs/supported-features-50)\n\nConnections and databases\n-------------------------\n\n- Each connection is limited to a single Firestore with MongoDB compatibility database.\n- A database must be created before connecting to it.\n\nNaming\n------\n\nThe following differences apply to naming parts of your data model.\n\n### Collections\n\n- Collection names matching `__.*__` are not supported.\n\n### Fields\n\n- Field names matching `__.*__` are not supported.\n- Empty field names are not supported.\n\nDocuments\n---------\n\n- The maximum document size is 4 MiB.\n- The maximum nesting depth of fields is 20. Each Array and Object-typed field adds one level to the overall depth.\n\n### `_id`\n\n- Document `_id` (top-level field) must be an ObjectId, String, or 64-bit integer. Other BSON types are not supported.\n- Empty string (\"\") and 64-bit 0 (0L) are not supported.\n\nValues\n------\n\n- The JavaScript, Symbol, DBPointer, and Undefined BSON types are not supported.\n\n### Date\n\n- Date values must fall in `[0001-01-01T00:00:00Z, 9999-12-31T23:59:59Z]`.\n\n### Decimal128\n\n- `NaN`, positive infinity, and negative infinity values are canonicalized on write.\n- Arithmetic operations on Decimal128 are not supported.\n\n### Double\n\n- `NaN` values are canonicalized on write.\n\n### Regular expression\n\n- Regular expression options must be valid (\"i\", \"m\", \"s\", \"u\", or \"x\") and provided in alphabetical order without repeats.\n\nQueries\n-------\n\n- Natural sort order (queries without an explicit sort) does not match insertion order or order by `_id` ascending.\n\nAggregations\n------------\n\n- Aggregations are limited to 250 stages.\n- The `$merge` and `$out` stages are not supported. See the [commands](#commands) section for a complete list of supported stages and operators.\n- The `$lookup` stage is limited to specifying a `foreignField` on `_id`.\n\nWrites\n------\n\n- Documents with names beginning with a dollar sign (\"$\") cannot be created using the upsert feature of `update` or `findAndModify`.\n- Make sure your connection string includes `retryWrites=false` (or use the method appropriate to your driver) to make sure the driver does not attempt to use this feature. Retryable writes are not supported.\n\nTransactions\n------------\n\n- Snapshot isolation and serializable transactions are\n supported.\n\n- By default, transactions use optimistic concurrency controls\n with snapshot isolation.\n\nRead concern\n------------\n\n- Firestore with MongoDB compatibility supports the `snapshot` , `majority`, and `linearizable`\n read concerns. The default is `snapshot` which refers to snapshot isolation.\n\n Use `linearizable` when the application requires strict consistency\n and must prevent write skew anomalies. For other workloads,\n `snapshot` can improve performance and reduce transaction contention.\n\nWrite concern\n-------------\n\n- Only `w: 'majority'` and `w: 1` write concerns are supported.\n\nRead preference\n---------------\n\n- Only the `primary`, `primaryPreferred`, `primary_preferred`, `secondary_preferred`, and `nearest` read concerns are supported.\n\nIndexes\n-------\n\n- Wildcard indexes are not supported.\n- Firestore with MongoDB compatibility does not automatically create an index on `_id`, but it ensures values of `_id` are unique within a collection.\n- Indexes without multi-key enabled are not automatically changed to [multi-key indexes](/firestore/mongodb-compatibility/docs/index-overview#multi-key_indexes_for_array_values) based on write operations. You must enable multi-key when you create the index and the option cannot be changed.\n\nErrors\n------\n\n- Error codes and messages may differ between Firestore with MongoDB compatibility and MongoDB.\n\nCommands\n--------\n\nThe following behavior differences apply to specific commands.\n\n- Commands not listed in the following tables are unsupported.\n- `maxTimeMS` is accepted by most commands but may be ignored.\n\n### Queries and writes\n\n### Transactions and sessions\n\n### Administration\n\nWhat's next\n-----------\n\n- Run the [Quickstart: Create a database and connect to it](/firestore/mongodb-compatibility/docs/create-and-query-database).\n- For a full list of supported features, see [Supported MongoDB data types, drivers, and features](/firestore/mongodb-compatibility/docs/supported-data-types-drivers)."]]