2008-06-06 15:43:15 +02:00
|
|
|
// query.h
|
|
|
|
|
2008-07-20 23:37:33 +02:00
|
|
|
/**
|
|
|
|
* Copyright (C) 2008 10gen Inc.
|
2008-12-29 02:28:49 +01:00
|
|
|
*
|
2008-07-20 23:37:33 +02:00
|
|
|
* 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.
|
2008-12-29 02:28:49 +01:00
|
|
|
*
|
2008-07-20 23:37:33 +02:00
|
|
|
* 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.
|
2008-12-29 02:28:49 +01:00
|
|
|
*
|
2008-07-20 23:37:33 +02:00
|
|
|
* 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"
|
2009-02-03 19:30:28 +01:00
|
|
|
#include "../util/message.h"
|
2009-02-14 02:04:13 +01:00
|
|
|
#include "dbmessage.h"
|
2008-06-06 15:43:15 +02:00
|
|
|
#include "jsobj.h"
|
|
|
|
#include "storage.h"
|
|
|
|
|
2008-12-29 02:28:49 +01: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;
|
2008-12-29 02:28:49 +01:00
|
|
|
a series of JSObjects
|
2008-08-11 20:07:30 +02:00
|
|
|
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;
|
2009-08-11 20:34:45 +02:00
|
|
|
int nToReturn; // how many you want back as the beginning of the cursor data (0=no limit)
|
|
|
|
// greater than zero is simply a hint on how many objects to send back per "cursor batch".
|
|
|
|
// a negative number indicates a hard 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.
|
|
|
|
*/
|
|
|
|
|
2009-01-09 17:20:16 +01:00
|
|
|
// struct QueryOptions, QueryResult, QueryResultFlags in:
|
2008-10-20 00:46:53 +02:00
|
|
|
#include "../client/dbclient.h"
|
2008-06-06 15:43:15 +02:00
|
|
|
|
2009-01-14 23:09:51 +01:00
|
|
|
namespace mongo {
|
|
|
|
|
2009-10-01 16:01:02 +02:00
|
|
|
// for an existing query (ie a ClientCursor), send back additional information.
|
2009-12-30 05:30:29 +01:00
|
|
|
QueryResult* getMore(const char *ns, int ntoreturn, long long cursorid , CurOp& op);
|
2008-06-06 15:43:15 +02:00
|
|
|
|
2009-10-21 21:18:21 +02:00
|
|
|
struct UpdateResult {
|
|
|
|
bool existing;
|
|
|
|
bool mod;
|
|
|
|
unsigned long long num;
|
|
|
|
|
|
|
|
UpdateResult( bool e, bool m, unsigned long long n )
|
|
|
|
: existing(e) , mod(m), num(n ){}
|
|
|
|
|
|
|
|
int oldCode(){
|
|
|
|
if ( ! num )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ( existing ){
|
|
|
|
if ( mod )
|
|
|
|
return 2;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( mod )
|
|
|
|
return 3;
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-10-01 16:01:02 +02:00
|
|
|
/* returns true if an existing object was updated, false if no existing object was found.
|
|
|
|
multi - update multiple objects - mostly useful with things like $set
|
|
|
|
*/
|
2009-12-30 05:30:29 +01:00
|
|
|
UpdateResult updateObjects(const char *ns, BSONObj updateobj, BSONObj pattern, bool upsert, bool multi , bool logop , OpDebug& debug );
|
2008-07-31 15:58:08 +02:00
|
|
|
|
2009-01-28 21:24:52 +01:00
|
|
|
// If justOne is true, deletedId is set to the id of the deleted object.
|
2009-04-09 19:30:28 +02:00
|
|
|
int deleteObjects(const char *ns, BSONObj pattern, bool justOne, bool logop = false, bool god=false);
|
2008-06-06 15:43:15 +02:00
|
|
|
|
2009-03-24 17:12:04 +01:00
|
|
|
long long runCount(const char *ns, const BSONObj& cmd, string& err);
|
2009-01-21 16:36:40 +01:00
|
|
|
|
2009-12-30 05:30:29 +01:00
|
|
|
auto_ptr< QueryResult > runQuery(Message& m, QueryMessage& q, CurOp& curop );
|
2009-02-23 15:50:31 +01:00
|
|
|
|
2009-01-14 23:09:51 +01:00
|
|
|
} // namespace mongo
|
|
|
|
|
2008-06-06 20:59:58 +02:00
|
|
|
#include "clientcursor.h"
|