0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-24 08:30:56 +01:00
mongodb/db/query.cpp
2007-10-28 16:38:06 -04:00

52 lines
995 B
C++

// query.cpp
#include "stdafx.h"
#include "query.h"
#include "pdfile.h"
#include "jsobj.h"
#include "../util/builder.h"
int nextCursorId = 1;
QueryResult* runQuery(const char *ns, int ntoreturn, JSObj jsobj) {
cout << "runQuery ns:" << ns << " ntoreturn:" << ntoreturn << " queryobjsize:" <<
jsobj.objsize() << endl;
/* temp implementation -- just returns everything! */
BufBuilder b;
QueryResult *qr = 0;
b.skip(sizeof(QueryResult));
int n = 0;
Cursor c = theDataFileMgr.findAll(ns);
while( c.ok() ) {
Record *r = c.current();
JSObj js(r);
// check criteria here.
b.append(r->netLength()+4);
b.append(r->data, r->netLength());
n++;
if( n >= ntoreturn && ntoreturn != 0 )
break;
c.advance();
}
qr = (QueryResult *) b.buf();
qr->len = b.len();
qr->reserved = 0;
qr->operation = opReply;
qr->cursorId = 0; //nextCursorId++;
qr->startingFrom = 0;
qr->nReturned = n;
b.decouple();
return qr;
}