google-code-export / morphia

Automatically exported from code.google.com/p/morphia
1 stars 0 forks source link

why morphia query batchSize() limit() method can not be negative #422

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Morphia 0.99   source

public DBCursor prepareCursor() {
        DBObject query = getQueryObject();
        DBObject fields = getFieldsObject();

        if (log.isTraceEnabled())
            log.trace("Running query(" + dbColl.getName() + ") : " + query + ", fields:" + fields + ",off:" + offset + ",limit:" + limit);

        DBCursor cursor = dbColl.find(query, fields);
        if (offset > 0)
            cursor.skip(offset);
        if (limit > 0)
            cursor.limit(limit);
        if (batchSize > 0)
            cursor.batchSize(batchSize);
        if (snapshotted)
            cursor.snapshot();
        if (sort != null)
            cursor.sort(sort);
        if (indexHint != null)
            cursor.hint(indexHint);

        if (slaveOk) {
            int opts = dbColl.getOptions();
            cursor.addOption(opts |= Bytes.QUERYOPTION_SLAVEOK);
        }

        if (noTimeout) {
            int opts = dbColl.getOptions();
            cursor.addOption(opts |= Bytes.QUERYOPTION_NOTIMEOUT);
        }

        //Check for bad options.
        if (snapshotted && (sort!=null || indexHint!=null))
            log.warning("Snapshotted query should not have hint/sort.");

        return cursor;
    }
I look at mongodb driver find this 

If <tt>batchSize</tt> is negative, it will limit of number objects returned, 
that fit within the max batch size limit (usually 4MB), and cursor will be 
closed.
     * For example if <tt>batchSize</tt> is -10, then the server will return a maximum of 10 documents and as many as can fit in 4MB, then close the cursor.
     * Note that this feature is different from limit() in that documents must fit within a maximum size, and it removes the need to send a request to close the cursor server-side.

but morphia does not support ,why?

Original issue reported on code.google.com by dengqiao...@gmail.com on 27 Jul 2012 at 2:50