MSG packet

The MSG packet can be used for both request and responses, and is the more common format in recent uses of Mongo. Other packet types are still supported, but the MSG packet is preferred these days. For complete documentation on this packet type, see the MongoDB documentation.

Methods

int getFlagBits()
Returns an integer that can be a combination of the following:
0x00000001 : Checksum present - indicates that a checksum is present. You normally don't have to worry about that since the checksum is recomputed automatically if you change the packet
0x00000002 : More to come - Indicates that another message will follow this one
0x00010000 : Exhaust allowed - Set by the client to indicates that it will accept more using the moreToCome flag

void setFlagBits(int bits)
Used to change the flag bits. Rarely used.

List<MessageSection> getSections
Gets all the sections in the message. There will always be at least one. You cannot change the returned list -- use addSection and removeSection instead.

number getNumberOfSections()
Returns the number of sections in this packet. This is always 1 or greater.

MessageSection getSection(int index)
Get the section at the specified index (zero-based).

MessageSection addSection()
Adds a section to this packet.

MessageSection addSectionAtIndex(int)
Adds a section to this packet at the specified index (zero-based).

void removeSection(int index)
Removes the specified section from this packet.

string toString(int)
Returns a string representation of this packet up to the specified number of characters. MSG packets can be fairly large, so this is often useful to keep logging to a reasonable amount. The regular toString() method, which is invoked whenever printing a packet directly (as in log.debug(pkt) ), returns up to 300 characters, followed by "..." if it was truncated.

MessageSection

A MSG packet contains one or more sections, each of which has the following methods.

int getKind()
Will return either 0 to indicate that this MessageSection has a body attribute, or 1 to indicate that this MessageSection has a sequence of documents.

void setKind(int kind)
Changes the MessageSection kind, accepts only 0 or 1. Rarely used as a client would usually not expect such a drastic change.

boolean isBody()
Returns true if this MessageSection has a body attribute

void setIsBody()
Sets this MessageSection to have a body attribute.

boolean isSequence()
Returns true if this MessageSection has a sequence of documents

void setIsSequence()
Sets this MessageSection to have a sequence of documents

object getBody()
Returns the body for this MessageSection, assuming it is in fact a body section (i.e. isBody() == true)

void setBody(object)
Sets the body of this message section.

String getDocSequenceIdentifier()
Returns the document sequence identifier - rarely used.

void setDocSequenceIdentifier(String s)
Sets the document sequence identifier

List<object> getDocuments()
Returns all the documents in this MessageSection, assuming isSequence() == true. The list of documents cannot be altered, use addDocument() and removeDocument().

object getDocument(int index)
Returns the document at the specified index.

void addDocument(object)
Adds the specified document to the list.

void addDocumentAtIndex(object, int)
Add the specified document to the list, at the indicated index.

void removeDocument(int)
Removes the specified document from the list.