mongo::Query Class Reference

#include <dbclient.h>

List of all members.

Public Member Functions

Queryexplain ()
BSONObj getFilter () const
BSONObj getHint () const
BSONObj getSort () const
Queryhint (const string &jsonKeyPatt)
Queryhint (BSONObj keyPattern)
bool isComplex (bool *hasDollar=0) const
bool isExplain () const
QuerymaxKey (const BSONObj &val)
QueryminKey (const BSONObj &val)
 operator string () const
 Query (const char *json)
 Query (const string &json)
 Query (const BSONObj &b)
 Query ()
Querysnapshot ()
Querysort (const string &field, int asc=1)
Querysort (const BSONObj &sortPattern)
string toString () const
Querywhere (const string &jscode)
Querywhere (const string &jscode, BSONObj scope)

Public Attributes

BSONObj obj

Private Member Functions

template<class T >
void appendComplex (const char *fieldName, const T &val)
void makeComplex ()

Detailed Description

Represents a Mongo query expression. Typically one uses the QUERY(...) macro to construct a Query object. Examples: QUERY( "age" << 33 << "school" << "UCLA" ).sort("name") QUERY( "age" << GT << 30 << LT << 50 )

Definition at line 220 of file dbclient.h.


Constructor & Destructor Documentation

mongo::Query::Query (  )  [inline]

Definition at line 223 of file dbclient.h.

mongo::Query::Query ( const BSONObj b  )  [inline]

Definition at line 224 of file dbclient.h.

mongo::Query::Query ( const string &  json  )  [inline]

Definition at line 225 of file dbclient.h.

mongo::Query::Query ( const char *  json  )  [inline]

Definition at line 227 of file dbclient.h.


Member Function Documentation

template<class T >
void mongo::Query::appendComplex ( const char *  fieldName,
const T &  val 
) [inline, private]

Definition at line 313 of file dbclient.h.

Query& mongo::Query::explain (  ) 

Return explain information about execution of this query instead of the actual query results. Normally it is easier to use the mongo shell to run db.find(...).explain().

BSONObj mongo::Query::getFilter (  )  const
BSONObj mongo::Query::getHint (  )  const
BSONObj mongo::Query::getSort (  )  const
Query& mongo::Query::hint ( const string &  jsonKeyPatt  )  [inline]

Definition at line 253 of file dbclient.h.

Query& mongo::Query::hint ( BSONObj  keyPattern  ) 

Provide a hint to the query.

Parameters:
keyPattern Key pattern for the index to use. Example: hint("{ts:1}")
bool mongo::Query::isComplex ( bool *  hasDollar = 0  )  const

if this query has an orderby, hint, or some other field

bool mongo::Query::isExplain (  )  const
void mongo::Query::makeComplex (  )  [private]
Query& mongo::Query::maxKey ( const BSONObj val  ) 

max is exclusive

Query& mongo::Query::minKey ( const BSONObj val  ) 

Provide min and/or max index limits for the query. min <= x < max

mongo::Query::operator string (  )  const [inline]

Definition at line 309 of file dbclient.h.

Query& mongo::Query::snapshot (  ) 

Use snapshot mode for the query. Snapshot mode assures no duplicates are returned, or objects missed, which were present at both the start and end of the query's execution (if an object is new during the query, or deleted during the query, it may or may not be returned, even with snapshot mode).

Note that short query responses (less than 1MB) are always effectively snapshotted.

Currently, snapshot mode may not be used with sorting or explicit hints.

Query& mongo::Query::sort ( const string &  field,
int  asc = 1 
) [inline]

Add a sort (ORDER BY) criteria to the query expression. This version of sort() assumes you want to sort on a single field.

Parameters:
asc = 1 for ascending order asc = -1 for descending order

Definition at line 245 of file dbclient.h.

Query& mongo::Query::sort ( const BSONObj sortPattern  ) 

Add a sort (ORDER BY) criteria to the query expression.

Parameters:
sortPattern the sort order template. For example to order by name ascending, time descending: { name : 1, ts : -1 } i.e. BSON( "name" << 1 << "ts" << -1 ) or fromjson(" name : 1, ts : -1 ")
string mongo::Query::toString (  )  const
Query& mongo::Query::where ( const string &  jscode  )  [inline]

Definition at line 296 of file dbclient.h.

Query& mongo::Query::where ( const string &  jscode,
BSONObj  scope 
)

Queries to the Mongo database support a $where parameter option which contains a javascript function that is evaluated to see whether objects being queried match its criteria. Use this helper to append such a function to a query object. Your query may also contain other traditional Mongo query terms.

Parameters:
jscode The javascript function to evaluate against each potential object match. The function must return true for matched objects. Use the this variable to inspect the current object.
scope SavedContext for the javascript object. List in a BSON object any variables you would like defined when the jscode executes. One can think of these as "bind variables".

Examples: conn.findOne("test.coll", Query("{a:3}").where("this.b == 2 || this.c == 3")); Query badBalance = Query().where("this.debits - this.credits < 0");


Member Data Documentation

Definition at line 222 of file dbclient.h.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


mongodb
Author(s): Nate Koenig
autogenerated on Fri Jan 11 12:15:57 2013