Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
110 lines (91 sloc) 3.94 KB
using System;
using System.IO;
using System.Text;
using MongoDB.Driver.Bson;
namespace MongoDB.Driver.IO
{
/// <summary>
/// Description of QueryMessage.
/// </summary>
public class QueryMessage : RequestMessage
{
// MsgHeader header; // standard message header
// int32 opts; // query options. See QueryOptions for values
// cstring fullCollectionName; // "dbname.collectionname"
// int32 numberToSkip; // number of documents to skip when returning results
// int32 numberToReturn; // number of documents to return in the first OP_REPLY
// BSON query ; // query object. See below for details.
// [ BSON returnFieldSelector; ] // OPTIONAL : selector indicating the fields to return. See below for details.
#region "Properties"
private QueryOptions options;
public QueryOptions Options {
get { return options; }
set { options = value; }
}
private string fullCollectionName;
public string FullCollectionName {
get { return fullCollectionName; }
set { fullCollectionName = value; }
}
private Int32 numberToSkip;
public int NumberToSkip {
get { return numberToSkip; }
set { numberToSkip = value; }
}
private Int32 numberToReturn;
public int NumberToReturn {
get { return numberToReturn; }
set { numberToReturn = value; }
}
private Document query;
public Document Query {
get { return query; }
set { query = value; }
}
private Document returnFieldSelector;
public Document ReturnFieldSelector {
get { return returnFieldSelector; }
set { returnFieldSelector = value; }
}
#endregion
#region "Ctors"
public QueryMessage(){
this.Header = new MessageHeader(OpCode.Query);
}
public QueryMessage(Document query, String fullCollectionName)
:this(query,fullCollectionName,0,0){
}
public QueryMessage(Document query, String fullCollectionName, Int32 numberToReturn, Int32 numberToSkip)
:this(query,fullCollectionName,numberToReturn, numberToSkip, null){
}
public QueryMessage(Document query, String fullCollectionName, Int32 numberToReturn,
Int32 numberToSkip, Document returnFieldSelector){
this.Header = new MessageHeader(OpCode.Query);
this.Query = query;
this.FullCollectionName = fullCollectionName;
this.NumberToReturn = numberToReturn;
this.NumberToSkip = NumberToSkip;
this.ReturnFieldSelector = returnFieldSelector;
}
#endregion
protected override void WriteBody (BsonWriter writer){
writer.WriteValue(BsonDataType.Integer,(int)this.Options);
writer.WriteString(this.FullCollectionName);
writer.WriteValue(BsonDataType.Integer,(int)this.NumberToSkip);
writer.WriteValue(BsonDataType.Integer,(int)this.NumberToReturn);
writer.Write(this.Query);
if(this.ReturnFieldSelector != null){
writer.Write(this.ReturnFieldSelector);
}
}
protected override int CalculateBodySize(BsonWriter writer){
int size = 12; //options, numbertoskip, numbertoreturn
size += writer.CalculateSize(this.FullCollectionName,false);
size += writer.CalculateSize(this.Query);
if(this.ReturnFieldSelector != null){
size += writer.CalculateSize(this.ReturnFieldSelector);
}
return size;
}
}
}
Something went wrong with that request. Please try again.