MongoDBx::Protocol - pure perl implementation of MongoDB protocol
version 0.03
my $p = MongoDBx::Protocol->new; my $msg = $p->insert({ header => { requestID => 3, responseTo => 2 }, fullCollectionName => 'test.test', documents => [ { a => b }, { c => d } ], }); my $sock = IO::Socket::INET->new( PeerAddr => 'localhost', PeerPort => 27017, Proto => 'tcp' ); $sock->print($msg);
This is a pure perl implementation of MongoDB protocol as described at http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol. Such modules as MongoDB and AnyMongo haven't public API for dealing with MongoDB protocol at low level. Using MongoDBx::Protocol you can encode/decode messages which you can send/recieve to/from MongoDB.
This module doesn't try to work very effectively, for this purposes you should use some XS code from MongoDB module.
For encoding and decoding BSON documents this module uses BSON module.
All encoding/decoding methods takes/returns hashref. See the key names for hashes and detailed description of this keys at MongoDB site.
Creates new instance of MongoDBx::Protocol.
Returns binary string that represents updating a documents in MongoDB.
$options is a hashref that contains following keys:
$options
Hashref with requestID and responseTo keys. Default value for this keys is 0.
requestID
responseTo
Hashref with possible flags Upsert, MultiUpdate.
Upsert
MultiUpdate
Fully qualified name of colllection (for example, "foo.bar").
Hashref that will be passed to BSON module for encoding to BSON document.
This hashref represents the query to select the document.
Hashref with specification of the update to perform.
$options contains:
Possible flag is ContinueOnError.
ContinueOnError
Arrayref of documents that will be encoded to BSON.
Possible flags are: TailableCursor, SlaveOk, OplogReplay, NoCursorTimeout, AwaitData, Exhaust, Partial.
TailableCursor
SlaveOk
OplogReplay
NoCursorTimeout
AwaitData
Exhaust
Partial
Default is 0.
Default is 1.
Which fields will be returned.
64-bit cursorID recieved from MongoDB during OP_QUERY.
Possible flag is SingleRemove.
SingleRemove
Arrayref of cursorIDs.
String with message.
MongoDB docs marked this method as deprecated for clients.
Possible flags are: CursorNotFound, QueryFailure, ShardConfigStale, AwaitCapable.
CursorNotFound
QueryFailure
ShardConfigStale
AwaitCapable
Arrayref of documents.
Opposite to encode methods. Takes binary string $data and returns hashref with parsed data in the same format as it uses to encode.
$data
$options is a hashref. Now it can contain ixhash flag, it says that documents should be returned as Tie::IxHash for preserving keys order in the hash.
ixhash
Works only on 64-bit Perl. I'll fix it soon.
http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol
BSON, MongoDB, AnyMongo
Yury Zavarin <yury.zavarin@gmail.com>
This software is copyright (c) 2011 by Yury Zavarin.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install MongoDBx::Protocol, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MongoDBx::Protocol
CPAN shell
perl -MCPAN -e shell install MongoDBx::Protocol
For more information on module installation, please visit the detailed CPAN module installation guide.