Exemplo n.º 1
0
/*
 * has_more = cursor:has_more(in_current_batch)
 *    pass true to call moreInCurrentBatch (mongo >=1.5)
 */
static int cursor_has_more(lua_State *L) {
    DBClientCursor *cursor = userdata_to_cursor(L, 1);

    bool in_current_batch = lua_toboolean(L, 2);
    if (in_current_batch)
        lua_pushboolean(L, cursor->moreInCurrentBatch());
    else
        lua_pushboolean(L, cursor->more());

    return 1;
}
Exemplo n.º 2
0
/*
 * res = cursor:next()
 */
static int cursor_next(lua_State *L) {
    DBClientCursor *cursor = userdata_to_cursor(L, 1);

    if (cursor->more()) {
        bson_to_lua(L, cursor->next());
    } else {
        lua_pushnil(L);
    }

    return 1;
}
Exemplo n.º 3
0
static int result_iterator(lua_State *L) {
    DBClientCursor *cursor = userdata_to_cursor(L, lua_upvalueindex(1));

    if (cursor->more()) {
        bson_to_lua(L, cursor->next());
    } else {
        lua_pushnil(L);
    }

    return 1;
}
Exemplo n.º 4
0
// "./db testclient" to invoke
    void testClient3() {
        out() << "testClient()" << endl;
//	DBClientConnection c(true);
        DBClientPaired c;
        string err;
        if ( !c.connect("10.211.55.2", "1.2.3.4") ) {
//    if( !c.connect("10.211.55.2", err) ) {
            out() << "testClient: connect() failed" << endl;
        }
        else {
            // temp:
            out() << "test query returns: " << c.findOne("foo.bar", fromjson("{}")).toString() << endl;
        }
again:
        out() << "query foo.bar..." << endl;
        auto_ptr<DBClientCursor> cursor =
            c.query("foo.bar", BSONObj(), 0, 0, 0, Option_CursorTailable);
        DBClientCursor *cc = cursor.get();
        if ( cc == 0 ) {
            out() << "query() returned 0, sleeping 10 secs" << endl;
            sleepsecs(10);
            goto again;
        }
        while ( 1 ) {
            bool m;
            try {
                m = cc->more();
            } catch (AssertionException&) {
                out() << "more() asserted, sleeping 10 sec" << endl;
                goto again;
            }
            out() << "more: " << m << " dead:" << cc->isDead() << endl;
            if ( !m ) {
                if ( cc->isDead() )
                    out() << "cursor dead, stopping" << endl;
                else {
                    out() << "Sleeping 10 seconds" << endl;
                    sleepsecs(10);
                    continue;
                }
                break;
            }
            out() << cc->next().toString() << endl;
        }
    }
Exemplo n.º 5
0
 JSBool internal_cursor_hasNext(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){
     DBClientCursor *cursor = getCursor( cx, obj );
     *rval = cursor->more() ? JSVAL_TRUE : JSVAL_FALSE;
     return JS_TRUE;
 }