$in operator

6 views
Skip to first unread message

Revant Jain

unread,
May 1, 2012, 3:45:47 PM5/1/12
to mongodb-user
suppose i use

db.test.find("{ num : { $in : [1, 2, 3] }")

is the search going to to sequential O(n), is sorted array is passed
can search be binary with O(log(n))?

Eliot Horowitz

unread,
May 1, 2012, 10:37:11 PM5/1/12
to mongod...@googlegroups.com
It'll basically do each one in serial.
A regular query like { num : 1 } is log(n) (where n = size of collection.
So it would be O( m * log(n) ) where m is the size of the $in array
> --
> 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.
>
Message has been deleted

Andreas Jung

unread,
May 2, 2012, 3:10:38 AM5/2/12
to mongod...@googlegroups.com
Well, create an index and you are fine :-)

-aj

Revant Jain wrote:
> suppose,
>
> db.test.find({ num : { $in : [1,2,3,4] } });
>
> if the array has over 100 elements, is the array search against num
> field sequential (O(n)) or binary (O(log(n))?
>

--
ZOPYX Limited | zopyx group
Charlottenstr. 37/1 | The full-service network for Zope & Plone
D-72070 T�bingen | Produce & Publish
www.zopyx.com | www.produce-and-publish.com
------------------------------------------------------------------------
E-Publishing, Python, Zope & Plone development, Consulting


Reply all
Reply to author
Forward
0 new messages