[DOCS-13314] warn about the risks of using subdocument as the value of _id Created: 20/Dec/19  Updated: 30/Oct/23

Status: Closed
Project: Documentation
Component/s: manual, Server
Affects Version/s: None
Fix Version/s: Server_Docs_20231030

Type: Improvement Priority: Minor - P4
Reporter: Mark Callaghan (Inactive) Assignee: Unassigned
Resolution: Won't Do Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 1 year, 14 weeks, 2 days ago
Epic Link: DOCSP-1769

 Description   

Description

The context is someone (me) with more SQL than Mongo experience. I think more should be done to warn about the risks of:
1) using a subdocument as the value of _id
2) searching by value for a subdocument, whether or not there is an index

I think this is important because not doing this correctly means a user can get incorrect query results – either data won't be found or wrong data will be returned.

https://docs.mongodb.com/manual/tutorial/query-embedded-documents/ states
"Equality matches on the whole embedded document require an exact match of the specified <value> document, including the field order."
... but does not explain that whether field order can be guaranteed is driver dependent

This page has examples but no warnings about the driver dependency
https://docs.mongodb.com/manual/reference/method/db.collection.find/#query-embedded-documents

This page has examples and a brief warning about field order without mentioning the driver dependency:
https://docs.mongodb.com/manual/core/index-single/#create-an-index-on-embedded-document
"When performing equality matches on embedded documents, field order matters and the embedded documents must match exactly"

By driver dependency I mean that the client encodes BSON and there must be a way for clients to enforce the order in which fields will be encoded. I assume that Son does this for Python. The SON doc page is vague about why key order matters:
[https://api.mongodb.com/python/current/api/bson/son.html
]"Regular dictionaries can be used instead of SON objects, but not when the order of keys is important."

This page has a great description of the problem and solution. I hope something like it can be mentioned in the manual.
https://emptysqua.re/blog/pymongo-key-order

And one of our co-workers has a nice answer at https://softwareengineering.stackexchange.com/questions/319468/why-does-mongodb-check-for-order-of-keys-when-matching-embedded-documents

Scope of changes

Impact to Other Docs

MVP (Work and Date)

Resources (Scope or Design Docs, Invision, etc.)



 Comments   
Comment by Education Bot [ 31/Oct/22 ]

Hello! This ticket has been closed due to inactivity. If you believe this ticket is still important, please reopen it and leave a comment to explain why. Thank you!

Comment by Mark Callaghan (Inactive) [ 22/Dec/19 ]

The manual – I might have tagged this incorrectly.

Comment by Ravind Kumar (Inactive) [ 20/Dec/19 ]

mark.callaghan to confirm, do you mean for us to add clarification to the manual, or to the BI Connector docs (baas-docs label?)

Generated at Thu Feb 08 08:07:28 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.