0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00
mongodb/db/query.h

111 lines
2.8 KiB
C
Raw Normal View History

2007-10-20 01:35:48 +02:00
// query.h
#pragma once
#include "../stdafx.h"
#include "../grid/message.h"
2007-10-28 21:38:06 +01:00
#include "jsobj.h"
2007-11-05 01:17:42 +01:00
#include "storage.h"
2007-10-20 01:35:48 +02:00
2007-10-28 19:42:59 +01:00
/* requests:
2007-10-30 10:50:14 +01:00
dbDelete
int reserved=0;
string collection;
int flags=0; // 1=DeleteSingle
JSObject query;
dbUpdate:
int reserved;
string collection;
int flags; // 1=upsert
JSObject query;
JSObject objectToUpdate;
2007-12-25 02:59:58 +01:00
objectToUpdate may include { $inc: <field> }.
2007-10-30 10:50:14 +01:00
dbQuery:
2007-10-28 19:42:59 +01:00
int reserved;
string collection;
2008-02-01 01:10:52 +01:00
int nToSkip;
2007-10-28 19:42:59 +01:00
int nToReturn; // how many you want back as the beginning of the cursor data
JSObject query;
2007-11-05 04:34:37 +01:00
[JSObject fieldsToReturn]
2007-10-30 10:50:14 +01:00
dbGetMore:
2007-11-04 22:17:44 +01:00
int reserved;
string collection; // redundant, might use for security.
2007-10-28 19:42:59 +01:00
int nToReturn;
2007-11-04 22:17:44 +01:00
int64 cursorID;
2008-02-13 06:26:39 +01:00
dbKillCursors=2007
int reserved;
int n;
int64 cursorIDs[n];
2007-10-30 10:50:14 +01:00
Note that on Update, there is only one object, which is different
from insert where you can pass a list of objects to insert in the db.
Note that the update field layout is very similar layout to Query.
2007-10-28 19:42:59 +01:00
*/
/* db response format
2007-10-20 01:35:48 +02:00
Query or GetMore:
int reserved;
2007-10-28 19:42:59 +01:00
int64 cursorID;
int startingFrom;
2007-10-28 21:38:06 +01:00
int nReturned; // 0=infinity
2007-10-20 01:35:48 +02:00
list of marshalled JSObjects;
2007-10-28 21:38:06 +01:00
*/
2007-10-20 01:35:48 +02:00
#pragma pack(push)
#pragma pack(1)
2007-10-20 01:35:48 +02:00
struct QueryResult : public MsgData {
2007-10-28 19:42:59 +01:00
long long cursorId;
int startingFrom;
2007-10-20 01:35:48 +02:00
int nReturned;
2007-10-28 21:38:06 +01:00
const char *data() { return (char *) (((int *)&nReturned)+1); }
2007-10-20 01:35:48 +02:00
};
#pragma pack(pop)
2007-11-04 22:17:44 +01:00
QueryResult* getMore(const char *ns, int ntoreturn, long long cursorid);
2007-11-05 04:34:37 +01:00
2008-02-01 01:10:52 +01:00
QueryResult* runQuery(const char *ns, int ntoskip, int ntoreturn,
2007-12-01 17:44:42 +01:00
JSObj j, auto_ptr< set<string> > fieldFilter,
stringstream&);
2007-10-20 01:35:48 +02:00
2007-10-30 10:50:14 +01:00
void updateObjects(const char *ns, JSObj updateobj, JSObj pattern, bool upsert);
void deleteObjects(const char *ns, JSObj pattern, bool justOne);
2007-11-04 22:17:44 +01:00
2007-11-11 20:21:02 +01:00
/* Cursor -- and its derived classes -- are our internal cursors.
ClientCursor is a wrapper that represents a cursorid from our client
application's perspective.
*/
2007-11-04 22:17:44 +01:00
class Cursor;
class ClientCursor {
public:
ClientCursor() { cursorid=0; pos=0; }
2007-11-05 01:17:42 +01:00
~ClientCursor();
2007-11-04 22:17:44 +01:00
long long cursorid;
string ns;
auto_ptr<JSMatcher> matcher;
auto_ptr<Cursor> c;
int pos;
2007-11-05 01:17:42 +01:00
DiskLoc lastLoc;
2007-11-05 04:34:37 +01:00
auto_ptr< set<string> > filter;
2007-11-05 01:17:42 +01:00
2007-11-11 20:21:02 +01:00
/* report to us that a new clientcursor exists so we can track it. You still
do the initial updateLocation() yourself.
*/
static void add(ClientCursor*);
/* call when cursor's location changes so that we can update the
cursorsbylocation map. if you are locked and internally iterating, only
need to call when you are ready to "unlock".
*/
2007-11-05 01:17:42 +01:00
void updateLocation();
2007-11-04 22:17:44 +01:00
};
2007-11-11 20:21:02 +01:00
typedef map<long long, ClientCursor*> CCMap;
extern CCMap clientCursors; /* cursorid -> ClientCursor */
long long allocCursorId();