I am new to mongo db and I was going through transactions in the mongoDb documentations and find this part confusing. https://www.mongodb.com/docs/manual/core/transactions/ "Because you can use embedded documents and arrays to capture relationships between data in a single document structure instead of normalizing across multiple documents and collections"
In this context does array also include array of primitive types? As in, if my document only has array of primitive types and no embedded documents do I still need to use transaction?
What the documentation is eluding to is you do not need to use transaction if you are only updating a single document as it is already atomic.
Certain cross document or cross collections relationships can be modeled using a single document with embedded object and arrays. If you can model your scenario to use a single document you do not need to use transactions all at.
{
name : "Father",
id : 1,
children: [
{ name : "Jack" , age : 13 , parent: 1},
{ name : "Jil" , age : 5, parent: 1}
]
}
can be a single document instead of two Parent
and a Child
collections.
In your case it doesn't matter whether array is primitive or not so long as it doesn't have a cross document or cross collection reference