Do Querries on large embedded Arrays kill performance?

856 views
Skip to first unread message

Marc Seeger

unread,
Mar 19, 2010, 8:49:16 AM3/19/10
to mongodb-user
Hi,
Take this example:
You try to build something like a filesystem index in mongodb:

[FOLDER] => [File1, File2, File3, ... FileN]

You have to check if a certain File is a already in a certain Folder
(only the name-strings, not the actual content!).
=> file_is_in_folder = !collection.find_one({:folder =>
folder_name, :files => file_name}).nil?

This seems to take a really long time for large (10.000+) collections
of filenames.
Is there any way that this could be speed up (aka: do indexes help on
embedded arrays).
If not: would putting the filenames as documents and setting an index
on foldername+filename help?

Michael Dirolf

unread,
Mar 19, 2010, 8:59:45 AM3/19/10
to mongod...@googlegroups.com
You should index on the embedded array. See:
http://www.mongodb.org/display/DOCS/Multikeys

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>

Marc Seeger

unread,
Mar 19, 2010, 9:55:29 AM3/19/10
to mongodb-user
If I only do queries for {:folder =>
folder_name, :files => file_name}, shouldn't I somehow make a compound
index?
Will making a compound index over the Folder and the Filenames-Array
automatically make a multikey on the embedded array?

Michael Dirolf

unread,
Mar 19, 2010, 10:01:17 AM3/19/10
to mongod...@googlegroups.com
Ah sorry I missed that your queries looked like that. Yes you should
use a compound index - it will work w/ multikeys.
Reply all
Reply to author
Forward
0 new messages