CSMongo.Requests.QueryRequest.GenerateBody C# (CSharp) Method

GenerateBody() protected method

Creates the body of the request to send
protected GenerateBody ( DynamicStream stream ) : void
stream CSMongo.IO.DynamicStream
return void
        protected override void GenerateBody(DynamicStream stream)
        {
            //determine the correct options to use
            stream.Append(BsonTranslator.AsInt32((int)this.Options));

            //apply the collection and database
            stream.Append(BsonTranslator.AsString(this.GetDatabaseTarget()));

            //update the range information for this request
            stream.Append(BsonTranslator.AsInt32(this.Skip));
            stream.Append(BsonTranslator.AsInt32(this.Take));

            //generate the query
            stream.Append(this.Parameters.ToBsonByteArray());

            //generate the field selectors if there are any
            if (this.Fields.Count > 0) {

                //create the selector document
                BsonDocument select = new BsonDocument();
                for (int i = 0; i < this.Fields.Count; i++) {
                    select.Set(this.Fields[i], i + 1);
                }

                //append the bytes
                stream.Append(select.ToBsonByteArray());

            }
        }