oferfort
unread,May 5, 2011, 4:32:52 PM5/5/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mongodb-user
Hey all,
i have a sharded collection and i'm querying by _id.
Usually i'm using findOne and it works ok, but today i decided to see
if find($in, {_id: array}) would be any better.
After a few tests i realized that for a small amount of ids findOne
for each is actually faster, but for a few hundreds or thousands of
ids, the $in method is quicker.
I was happy for a while, untill i started getting stuck, and thread
dump showed all my threads stuck on cursor.hasNext()
"Thread-786" prio=5 id=808 RUNNABLE
java.net.SocketInputStream.socketRead0(Native Method)
java.net.SocketInputStream.read(SocketInputStream.java:129)
java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
java.io.BufferedInputStream.read1(BufferedInputStream.java:
258)
java.io.BufferedInputStream.read(BufferedInputStream.java:317)
org.bson.io.Bits.readFully(Bits.java:35)
org.bson.io.Bits.readFully(Bits.java:28)
com.mongodb.Response.<init>(Response.java:35)
com.mongodb.DBPort.go(DBPort.java:110)
com.mongodb.DBPort.go(DBPort.java:75)
com.mongodb.DBPort.call(DBPort.java:65)
com.mongodb.DBTCPConnector.call(DBTCPConnector.java:201)
com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:
295)
com.mongodb.DBCursor._check(DBCursor.java:354)
com.mongodb.DBCursor._hasNext(DBCursor.java:484)
com.mongodb.DBCursor.hasNext(DBCursor.java:509)
My code is pretty simple:
BasicDBObject query = new BasicDBObject();
query.put("_id", new BasicDBObject("$in", ids));
DBCursor result = db.getCollection(table).find(new
BasicDBObject(query));
while (result.hasNext())
{
DBObject object = result.next();
objects.put(object.get("_id"), object.toMap());
}
i'm using mongo 1.8.1 and a 2.5.3 java driver.
thanks for any insights
ofer