2008-06-06 15:43:15 +02:00
|
|
|
// query.h
|
|
|
|
|
2008-07-20 23:37:33 +02:00
|
|
|
/**
|
|
|
|
* Copyright (C) 2008 10gen Inc.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-06-06 15:43:15 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../stdafx.h"
|
|
|
|
#include "../grid/message.h"
|
|
|
|
#include "jsobj.h"
|
|
|
|
#include "storage.h"
|
|
|
|
|
2008-08-11 20:07:30 +02:00
|
|
|
/* db request message format
|
2008-06-06 15:43:15 +02:00
|
|
|
|
2008-08-11 20:07:30 +02:00
|
|
|
unsigned opid; // arbitary; will be echoed back
|
|
|
|
byte operation;
|
|
|
|
int options;
|
|
|
|
|
|
|
|
then for:
|
|
|
|
|
|
|
|
dbInsert:
|
|
|
|
string collection;
|
|
|
|
a series of JSObjects terminated with a null object (i.e., just EOO)
|
|
|
|
dbDelete:
|
2008-06-06 15:43:15 +02:00
|
|
|
string collection;
|
|
|
|
int flags=0; // 1=DeleteSingle
|
|
|
|
JSObject query;
|
|
|
|
dbUpdate:
|
|
|
|
string collection;
|
|
|
|
int flags; // 1=upsert
|
|
|
|
JSObject query;
|
|
|
|
JSObject objectToUpdate;
|
2008-08-19 00:00:17 +02:00
|
|
|
objectToUpdate may include { $inc: <field> } or { $set: ... }, see struct Mod.
|
2008-06-06 15:43:15 +02:00
|
|
|
dbQuery:
|
|
|
|
string collection;
|
|
|
|
int nToSkip;
|
2008-10-14 20:02:43 +02:00
|
|
|
int nToReturn; // how many you want back as the beginning of the cursor data (0=no limit)
|
2008-06-06 15:43:15 +02:00
|
|
|
JSObject query;
|
|
|
|
[JSObject fieldsToReturn]
|
|
|
|
dbGetMore:
|
|
|
|
string collection; // redundant, might use for security.
|
|
|
|
int nToReturn;
|
|
|
|
int64 cursorID;
|
|
|
|
dbKillCursors=2007:
|
|
|
|
int n;
|
|
|
|
int64 cursorIDs[n];
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2008-08-12 16:30:27 +02:00
|
|
|
// see dbclient.h for query options enum
|
2008-08-11 20:07:30 +02:00
|
|
|
|
2008-06-06 15:43:15 +02:00
|
|
|
/* db response format
|
|
|
|
|
2008-08-11 20:07:30 +02:00
|
|
|
Query or GetMore: // see struct QueryResult
|
2008-08-13 18:17:18 +02:00
|
|
|
int resultFlags = 0;
|
2008-06-06 15:43:15 +02:00
|
|
|
int64 cursorID;
|
|
|
|
int startingFrom;
|
2008-10-14 20:02:43 +02:00
|
|
|
int nReturned;
|
2008-06-06 15:43:15 +02:00
|
|
|
list of marshalled JSObjects;
|
|
|
|
*/
|
|
|
|
|
2008-08-13 18:17:18 +02:00
|
|
|
/* the field 'resultFlags' above */
|
2008-08-11 20:07:30 +02:00
|
|
|
enum {
|
|
|
|
/* returned, with zero results, when getMore is called but the cursor id is not valid at the server. */
|
2008-08-13 18:17:18 +02:00
|
|
|
ResultFlag_CursorNotFound = 1
|
2008-08-11 20:07:30 +02:00
|
|
|
};
|
|
|
|
|
2008-07-28 00:36:47 +02:00
|
|
|
// grab struct QueryResult from:
|
|
|
|
#include "dbclient.h"
|
2008-06-06 15:43:15 +02:00
|
|
|
|
2008-07-31 15:58:08 +02:00
|
|
|
// for an existing query (ie a ClientCursor), send back additional information.
|
2008-06-06 15:43:15 +02:00
|
|
|
QueryResult* getMore(const char *ns, int ntoreturn, long long cursorid);
|
|
|
|
|
|
|
|
// caller must free() returned QueryResult.
|
2008-06-11 22:58:34 +02:00
|
|
|
QueryResult* runQuery(Message&, const char *ns, int ntoskip, int ntoreturn,
|
2008-06-06 15:43:15 +02:00
|
|
|
JSObj j, auto_ptr< set<string> > fieldFilter,
|
2008-08-13 18:17:18 +02:00
|
|
|
stringstream&, int queryOptions);
|
2008-06-06 15:43:15 +02:00
|
|
|
|
|
|
|
void updateObjects(const char *ns, JSObj updateobj, JSObj pattern, bool upsert, stringstream& ss);
|
2008-07-31 15:58:08 +02:00
|
|
|
|
2008-07-24 22:07:18 +02:00
|
|
|
int deleteObjects(const char *ns, JSObj pattern, bool justOne, bool god=false);
|
2008-06-06 15:43:15 +02:00
|
|
|
|
2008-06-06 20:59:58 +02:00
|
|
|
#include "clientcursor.h"
|