I have an array of items, of which I would to find the first matches in my mongo db.
The array is like this, but could be very long: ["item:9802", "item:15051", "item:10028", "item:6575", "item:2355"] What I need is the first three hits, that can be found in the mongo db. Not all IDs will exist.
I use the github.com/mongodb/mongo-ruby-driver. What I did was this
search_hash = {:id=>{"$in"=>["item:9802", "item:15051", "item:10028", "item:6575", "item:2355"]}}
found = coll.find(search_hash).to_a
But I find that this returns the exact same results (and in the same order) when I use a completely different order, like:
search_hash = {:id=>{"$in"=>["item:2355", "item:6575", "item:9802", "item:15051", "item:10028"]}}
It there anyway to get the first matches without having to loop over the array (which is very long) and perform a find on every loop? I'm pretty new to Mongo, so maybe this is a very simple question, but I hope that anyone can help me with this.