protected byte[] GenerateBody() { //http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol#MongoWireProtocol-OPQUERY //int32 opts; // query options //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. using (var stream = new MemoryStream()) { using (var writer = new BodyWriter(stream)) { //Number of docs to return: // 0 => the server will use the default return size; // -x => If the number is negative, then the database will return that number and close the cursor. // 1 => the server will treat it as -1 (closing the cursor automatically) var numOfDocsToReturn = NumberOfDocumentsToReturn ?? 0; if (numOfDocsToReturn > 0) { numOfDocsToReturn = numOfDocsToReturn * -1; } writer.Write((int)Options); writer.Write(FullCollectionName); writer.WriteTerminator(); writer.Write(NumberOfDocumentsToSkip ?? 0); writer.Write(numOfDocsToReturn); writer.WriteSelector(QuerySelector ?? new object()); if (DocumentSchema != null) { writer.WriteDocument(DocumentSchema); } return(stream.ToArray()); } } }
protected byte[] GenerateBody() { //http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol#MongoWireProtocol-OPINSERT //int32 ZERO; // 0 - reserved for future use //cstring fullCollectionName; // "dbname.collectionname" //BSON[] documents; // one or more documents to insert into the collection using (var stream = new MemoryStream()) { using (var writer = new BodyWriter(stream)) { writer.Write(0); writer.Write(FullCollectionName); writer.WriteTerminator(); foreach (var document in Documents) { writer.WriteDocument(document); } return(stream.ToArray()); } } }
protected byte[] GenerateBody() { //http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol#MongoWireProtocol-OPUPDATE //int32 ZERO; // 0 - reserved for future use //cstring fullCollectionName; // "dbname.collectionname" //int32 flags; // bit vector. see below //BSON selector; // the query to select the document //BSON document; // the document data to update with or insert using (var stream = new MemoryStream()) { using (var writer = new BodyWriter(stream)) { writer.Write(0); writer.Write(FullCollectionName); writer.WriteTerminator(); writer.Write((int)Mode); writer.WriteSelector(QuerySelector ?? new object()); writer.WriteDocument(Document); return(stream.ToArray()); } } }