MongoDB efficient dealing with embedded documents
Posted
by
Sebastian Nowak
on Stack Overflow
See other posts from Stack Overflow
or by Sebastian Nowak
Published on 2014-08-23T16:02:40Z
Indexed on
2014/08/23
16:20 UTC
Read the original article
Hit count: 242
Performance
|mongodb
I have serious trouble finding anything useful in Mongo documentation about dealing with embedded documents. Let's say I have a following schema:
{
_id: ObjectId,
...
data: [
{
_childId: ObjectId // let's use custom name so we can distinguish them
...
}
]
}
What's the most efficient way to remove everything inside
data
for particular_id
?What's the most efficient way to remove embedded document with particular
_childId
inside given_id
? What's the performance here, can_childId
be indexed in order to achieve logarithmic (or similar) complexity instead of linear lookup? If so, how?What's the most efficient way to insert a lot of (let's say a 1000) documents into
data
for given_id
? And like above, can we get O(n log n) or similar complexity with proper indexing?What's the most efficient way to get the count of documents inside
data
for given_id
?
© Stack Overflow or respective owner