SlideShare una empresa de Scribd logo
1 de 68
Descargar para leer sin conexión
One BSON

to RuleThem
David Golden
Staff Engineer, MongoDB


NY Perl Meetup • Dec 2016
This talk in a nutshell...
https://xkcd.com/927/
First... let's talk types
Know JSON?
{
"name":"Larry Wall",
"answer":42,
"boolean":true,
"nothing":null,
"mixed_type_stuff":[
"a",23,{"key":"value "}
]
}
MongoDB transmits
data as 'BSON'
BSON = 'Binary JSON'
Like JSON,
except when not
JSON BSON
schema-less schema-less
key-value pairs key-value pairs
text binary
6 types 21 types
unordered ordered
JSON/BSON types...
JSON BSON
document document
array array
null null
string string
boolean boolean
number int32
int64
float64 (double)
decimal128
binary (blob)
datetime
regular expression
javascript code
javascript code with data
"object id"
"minimum key"
"maximum key"
"timestamp"
(3 deprecated types)
Serializing Perl is hard
Start with JSON
JSON Perl
document hash reference
array array reference
null undef
string string
number number
boolean ???
JSON Perl
document hash reference
array array reference
null undef
string string
number number
boolean ???
Scalar
JSON Perl
document hash reference
array array reference
null undef
string string
number number
boolean ???
this way is OK Scalar
JSON Perl
document hash reference
array array reference
null undef
string string
number number
boolean ???
this way is NOT OK Scalar
use JSON;
my $n = 23;
say encode_json({n => $n});
# {"n":23}
use JSON;
my $n = 23;
say encode_json({n => $n});
# {"n":23}
$n =~ /^d+$/;
use JSON;
my $n = 23;
say encode_json({n => $n});
# {"n":23}
$n =~ /^d+$/;
say encode_json({n => $n});
# {"n":"23"}
Booleans?
JSON Perl
document hash reference
array array reference
null undef
string string
number number
boolean ???
Scalar
JSON Perl
document hash reference
array array reference
null undef
string string
number number
boolean ???
Scalar
boolean.pm
use boolean;
my $true = true;
my $false = false;
say ref $true;
# boolean
say ref $false
# boolean
But this is Perl...
TIMTOWTDI
...that's why we can't

have nice things
JSON Perl
document hash reference
array array reference
null undef
string string
number number
boolean ???
Scalar
boolean.pm
JSON Perl
document hash reference
array array reference
null undef
string string
number number
boolean ???
Scalar
	 0
	 1
	 boolean.pm	 JSON::XS::Boolean	 JSON::PP::Boolean	 JSON::Tiny::_Bool	 Mojo::JSON::_Bool	 Cpanel::JSON::XS::Boolean	 Types::Serialiser::Boolean	 ...
Now consider BSON
BSON Perl
document hash reference
array array reference
null undef
string
boolean
int32
int64
float64 (double)
decimal128
binary (blob)
datetime
regular expression
javascript code
javascript code with data
"object id"
"minimum key"
"maximum key"
"timestamp"
(3 deprecated types)
Scalar
BSON Perl
document hash reference
array array reference
null undef
string
boolean
int32
int64
float64 (double)
decimal128
binary (blob)
datetime
regular expression
javascript code
javascript code with data
"object id"
"minimum key"
"maximum key"
"timestamp"
(3 deprecated types)
Scalar
Lots of wrapper classes
Serializing Perl is hard
Serializing Perl is hard
Deserializing typed data is hard
1. string/number heuristics



2. wrapper classes
Back to my problem...
https://xkcd.com/927/
MongoDB Perl Driver
history and future
MongoDB-v0.x series
BSON codec written in XS
Heuristics configured via global variables
($MongoDB::BSON::looks_like_number)
Wrapper classes
boolean.pm, MongoDB::OID, MongoDB::BSON::Binary,
MongoDB::Code, ...
Goals
Provide a pure-Perl option for the Perl driver
Get rid of globals and use codec objects
Allow users to customize decoding to wrappers
Meanwhile on CPAN...
BSON.pm

Mango (for Mojolicious)
Each with their own set
of wrapper classes
With generally
incompatible APIs
Goals
Provide a pure-Perl option for the Perl driver
Get rid of globals and use codec objects
Allow users to customize decoding to wrappers
Provide standard, reusable BSON wrappers
We adopted BSON.pm
Pure-perl
Not widely used (so we can change it more)
Lots of wrappers (some with odd APIs)
Not tied to Mojolicious ecosystem
Needed a roadmap
Step 1.
Extract MongoDB BSON to a configurable
codec object
Define a standard, pluggable codec API
(Released with MongoDB-v1.0.0 in mid-2015 )
Step 2.
Adapt BSON.pm to provide the codec API
Adapt or extend wrappers to provide common
behaviors needed
Prepare BSON.pm for pluggable backends (e.g.
future BSON::XS)



(Released to CPAN as BSON-v1.0.0 in July)
Step 3.
Extract MongoDB XS code to BSON::XS



(Released to CPAN as BSON-XS-v0.2.0 in Oct)
Step 4.
Remove MongoDB codec from distribution
Add dependency on BSON.pm/BSON::XS
Make MongoDB wrapper classes into empty
subclasses of BSON.pm wrapper classes
(Planned for future MongoDB-v2.0.0 in 2017)
Hard parts...
Finding common
wrapper behavior
https://github.com/mongodb/mongo-perl-bson/blob/master/devel/bson-types-survey.md
14 pages!
# MongoDB::OID
my $oid1 = MongoDB::OID->new;
my $oid2 = MongoDB::OID->new(value => $id1->value);
my $oid3 = MongoDB::OID->new($id1->value);
my $oid4 = MongoDB::OID->new($id1);
# BSON::ObjectID
my $oid1 = BSON::ObjectId->new;
my $oid2 = BSON::ObjectId->new($string);
my $oid3 = BSON::ObjectId->new($binary_string);
# Mango::BSON::ObjectID
my $oid1 = Mango::BSON::ObjectID->new;
my $oid2 = Mango::BSON::ObjectID->new('1a2b3c4e5f60718293a4b5c6');
Revised or wrote new
BSON.pm wrapper classes
Goal: Let all MongoDB::* wrappers become
empty subclasses of BSON.pm wrappers
- Lots of constructor argument munging
- Lots of method name aliasing
- Sometimes had to deprecate and start over
Deciding type mapping
Scalar
Wrapper A
Wrapper B
Wrapper C
Wrapper D
Wrapper E
Wrapper F
BSON bytes Wrapper D
Or maybe just scalar

based on config?
Encode Decode
Perl type/class -> BSON type -> Perl type/class
-------------------------------------------------------------------
float[1] 0x01 DOUBLE float[2]
BSON::Double
-------------------------------------------------------------------
string[3] 0x02 UTF8 string[2]
BSON::String
-------------------------------------------------------------------
hashref 0x03 DOCUMENT hashref[4][5]
BSON::Doc
BSON::Raw
MongoDB::BSON::Raw[d]
Tie::IxHash
-------------------------------------------------------------------
arrayref 0x04 ARRAY arrayref
-------------------------------------------------------------------
BSON::Bytes 0x05 BINARY BSON::Bytes
scalarref
BSON::Binary[d]
MongoDB::BSON::Binary[d]
-------------------------------------------------------------------
n/a 0x06 UNDEFINED[d] undef
-------------------------------------------------------------------
BSON::OID 0x07 OID BSON::OID
BSON::ObjectId[d]
MongoDB::OID[d]
-------------------------------------------------------------------
boolean 0x08 BOOL boolean
BSON::Bool[d]
JSON::XS::Boolean
JSON::PP::Boolean
JSON::Tiny::_Bool
Mojo::JSON::_Bool
Cpanel::JSON::XS::Boolean
Types::Serialiser::Boolean
-------------------------------------------------------------------
BSON::Time 0x09 DATE_TIME BSON::Time
DateTime
DateTime::Tiny
Time::Moment
Mango::BSON::Time
-------------------------------------------------------------------
undef 0x0a NULL undef
-------------------------------------------------------------------
BSON::Regex 0x0b REGEX BSON::Regex
qr// reference
MongoDB::BSON::Regexp[d]
Perl type/class -> BSON type -> Perl type/class
-------------------------------------------------------------------
n/a 0x0c DBPOINTER[d] BSON::DBRef
-------------------------------------------------------------------
BSON::Code[6] 0x0d CODE BSON::Code
MongoDB::Code[6]
-------------------------------------------------------------------
n/a 0x0e SYMBOL[d] string
-------------------------------------------------------------------
BSON::Code[6] 0x0f CODEWSCOPE BSON::Code
MongoDB::Code[6]
-------------------------------------------------------------------
integer[7][8] 0x10 INT32 integer[2]
BSON::Int32
-------------------------------------------------------------------
BSON::Timestamp 0x11 TIMESTAMP BSON::Timestamp
MongoDB::Timestamp[d]
-------------------------------------------------------------------
integer[7] 0x12 INT64 integer[2][9]
BSON::Int64
Math::BigInt
Math::Int64
-------------------------------------------------------------------
BSON::MaxKey 0x7F MAXKEY BSON::MaxKey
MongoDB::MaxKey[d]
-------------------------------------------------------------------
BSON::MinKey 0xFF MINKEY BSON::MinKey
MongoDB::MinKey[d]



[d] Deprecated or soon to be deprecated.
[1] Scalar with "NV" internal representation no "PV"
representation, or a string that looks like a float if the
'prefer_numeric' option is true.
[2] If the 'wrap_numbers' option is true, numeric types will be wrapped
as BSON::Double, BSON::Int32 or BSON::Int64 as appropriate to ensure
round-tripping. If the 'wrap_strings' option is true, strings will
be wrapped as BSON::String, likewise.
[3] Scalar with "PV" representation and not identified as a number
by notes [1] or [7].
[4] If 'ordered' option is set, will return a tied hash that preserves
order (deprecated 'ixhash' option still works).
[5] If the document appears to contain a DBRef and a 'dbref_callback'
exists, that callback is executed with the deserialized document.
[6] Code is serialized as CODE or CODEWSCOPE depending on whether a
scope hashref exists in BSON::Code/MongoDB::Code.
[7] Scalar with "IV" internal representation and no "PV"
representation, or a string that looks like an integer if the
'prefer_numeric' option is true.
[8] Only if the integer fits in 32 bits.
[9] On 32-bit platforms, 64-bit integers are deserialized to
Math::BigInt objects (even if subsequently wrapped into
BSON::Int64 if 'wrap_scalars' is true).
From BSON.pm docs
Testing PP and XS
Use same tests for both
rsync tests from BSON.pm to BSON::XS
Tests load t/lib/CleanEnv.pm, which hides either
BSON::PP (from BSON.pm) or BSON::XS
Ensures both backends consume/produce

exact same BSON
use 5.008001;
use strict;
use warnings;
package CleanEnv;
# Tiny equivalent of Devel::Hide to disable BSON::XS
use lib map {
my ( $m, $c ) = ( $_, qq{die "Can't locate $_ (hidden)n"} );
sub { return unless $_[1] eq $m; open my $fh, "<", $c; return $fh }
} qw{BSON/XS.pm}; # Would be BSON/PP.pm for BSON::XS
# Keep environment from interfering with tests
$ENV{PERL_BSON_BACKEND} = "";
1;
BSON.pm t/lib/CleanEnv.pm
Dependency order
Typical Foo/Foo::XS pattern
User uses Foo's API
Foo delegates to XS methods if Foo::XS loads
*foo = has_xs() ? &Foo::XS::_foo : &Foo::_foo;
Foo dynamically adds Foo::XS as a dependency if
a compiler is detected
Our problem & solution
BSON::XS tests need BSON.pm wrappers

Didn't want wrappers as a common prereq


Users can check for a compiler and add
BSON.pm or BSON::XS
(Or perhaps I'll just write BSON::MaybeXS)
Standardization is hard
https://xkcd.com/927/
but it can be done
Lessons learned
Serializing needs heuristics and wrapper classes
Type mapping is complex and unfun, but needed
Common tests for PP/XS are a life-saver
Look for MongoDB

Perl driver v2.0.0

next year!
Questions?
Email: david@mongodb.com

Twitter/IRC: @xdg

Más contenido relacionado

La actualidad más candente

A 2,000-BIT MESSAGE IS USED TO GENERATE A 256-BIT HASH. ONE THE AVERAGE, HOW ...
A 2,000-BIT MESSAGE IS USED TO GENERATE A 256-BIT HASH. ONE THE AVERAGE, HOW ...A 2,000-BIT MESSAGE IS USED TO GENERATE A 256-BIT HASH. ONE THE AVERAGE, HOW ...
A 2,000-BIT MESSAGE IS USED TO GENERATE A 256-BIT HASH. ONE THE AVERAGE, HOW ...SophiaMorgans
 
Data Modeling Deep Dive
Data Modeling Deep DiveData Modeling Deep Dive
Data Modeling Deep DiveMongoDB
 
Data Types/Structures in DivConq
Data Types/Structures in DivConqData Types/Structures in DivConq
Data Types/Structures in DivConqeTimeline, LLC
 
Building a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and JavaBuilding a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and Javaantoinegirbal
 
"Powerful Analysis with the Aggregation Pipeline (Tutorial)"
"Powerful Analysis with the Aggregation Pipeline (Tutorial)""Powerful Analysis with the Aggregation Pipeline (Tutorial)"
"Powerful Analysis with the Aggregation Pipeline (Tutorial)"MongoDB
 
MongoDB Advanced Schema Design - Inboxes
MongoDB Advanced Schema Design - InboxesMongoDB Advanced Schema Design - Inboxes
MongoDB Advanced Schema Design - InboxesJared Rosoff
 
Inside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source DatabaseInside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source DatabaseMike Dirolf
 
Dev Jumpstart: Schema Design Best Practices
Dev Jumpstart: Schema Design Best PracticesDev Jumpstart: Schema Design Best Practices
Dev Jumpstart: Schema Design Best PracticesMongoDB
 
Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.Andrii Lashchenko
 
Data Modeling for the Real World
Data Modeling for the Real WorldData Modeling for the Real World
Data Modeling for the Real WorldMike Friedman
 
MongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMike Friedman
 
Nested and Parent/Child Docs in ElasticSearch
Nested and Parent/Child Docs in ElasticSearchNested and Parent/Child Docs in ElasticSearch
Nested and Parent/Child Docs in ElasticSearchBeyondTrees
 
DrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and DrupalDrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and DrupalDoug Green
 
MongoDB London 2013: Data Modeling Examples from the Real World presented by ...
MongoDB London 2013: Data Modeling Examples from the Real World presented by ...MongoDB London 2013: Data Modeling Examples from the Real World presented by ...
MongoDB London 2013: Data Modeling Examples from the Real World presented by ...MongoDB
 
Webinar: Getting Started with MongoDB - Back to Basics
Webinar: Getting Started with MongoDB - Back to BasicsWebinar: Getting Started with MongoDB - Back to Basics
Webinar: Getting Started with MongoDB - Back to BasicsMongoDB
 
Test-driven development: a case study
Test-driven development: a case studyTest-driven development: a case study
Test-driven development: a case studyMaciej Pasternacki
 
Back to Basics Webinar 2: Your First MongoDB Application
Back to Basics Webinar 2: Your First MongoDB ApplicationBack to Basics Webinar 2: Your First MongoDB Application
Back to Basics Webinar 2: Your First MongoDB ApplicationMongoDB
 

La actualidad más candente (19)

A 2,000-BIT MESSAGE IS USED TO GENERATE A 256-BIT HASH. ONE THE AVERAGE, HOW ...
A 2,000-BIT MESSAGE IS USED TO GENERATE A 256-BIT HASH. ONE THE AVERAGE, HOW ...A 2,000-BIT MESSAGE IS USED TO GENERATE A 256-BIT HASH. ONE THE AVERAGE, HOW ...
A 2,000-BIT MESSAGE IS USED TO GENERATE A 256-BIT HASH. ONE THE AVERAGE, HOW ...
 
Data Modeling Deep Dive
Data Modeling Deep DiveData Modeling Deep Dive
Data Modeling Deep Dive
 
Data Types/Structures in DivConq
Data Types/Structures in DivConqData Types/Structures in DivConq
Data Types/Structures in DivConq
 
Building a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and JavaBuilding a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and Java
 
"Powerful Analysis with the Aggregation Pipeline (Tutorial)"
"Powerful Analysis with the Aggregation Pipeline (Tutorial)""Powerful Analysis with the Aggregation Pipeline (Tutorial)"
"Powerful Analysis with the Aggregation Pipeline (Tutorial)"
 
MongoDB Advanced Schema Design - Inboxes
MongoDB Advanced Schema Design - InboxesMongoDB Advanced Schema Design - Inboxes
MongoDB Advanced Schema Design - Inboxes
 
Inside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source DatabaseInside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source Database
 
Dev Jumpstart: Schema Design Best Practices
Dev Jumpstart: Schema Design Best PracticesDev Jumpstart: Schema Design Best Practices
Dev Jumpstart: Schema Design Best Practices
 
Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.
 
Data Modeling for the Real World
Data Modeling for the Real WorldData Modeling for the Real World
Data Modeling for the Real World
 
Mongo-Drupal
Mongo-DrupalMongo-Drupal
Mongo-Drupal
 
MongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World Examples
 
Nested and Parent/Child Docs in ElasticSearch
Nested and Parent/Child Docs in ElasticSearchNested and Parent/Child Docs in ElasticSearch
Nested and Parent/Child Docs in ElasticSearch
 
Hash crypto
Hash cryptoHash crypto
Hash crypto
 
DrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and DrupalDrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and Drupal
 
MongoDB London 2013: Data Modeling Examples from the Real World presented by ...
MongoDB London 2013: Data Modeling Examples from the Real World presented by ...MongoDB London 2013: Data Modeling Examples from the Real World presented by ...
MongoDB London 2013: Data Modeling Examples from the Real World presented by ...
 
Webinar: Getting Started with MongoDB - Back to Basics
Webinar: Getting Started with MongoDB - Back to BasicsWebinar: Getting Started with MongoDB - Back to Basics
Webinar: Getting Started with MongoDB - Back to Basics
 
Test-driven development: a case study
Test-driven development: a case studyTest-driven development: a case study
Test-driven development: a case study
 
Back to Basics Webinar 2: Your First MongoDB Application
Back to Basics Webinar 2: Your First MongoDB ApplicationBack to Basics Webinar 2: Your First MongoDB Application
Back to Basics Webinar 2: Your First MongoDB Application
 

Similar a One BSON to Rule Them

MongoDB - javascript for your data
MongoDB - javascript for your dataMongoDB - javascript for your data
MongoDB - javascript for your dataaaronheckmann
 
MongoDB - Javascript for your Data
MongoDB - Javascript for your DataMongoDB - Javascript for your Data
MongoDB - Javascript for your DataPaulo Fagundes
 
Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)Kai Zhao
 
Mongo db Quick Guide
Mongo db Quick GuideMongo db Quick Guide
Mongo db Quick GuideSourabh Sahu
 
Introduction to NOSQL And MongoDB
Introduction to NOSQL And MongoDBIntroduction to NOSQL And MongoDB
Introduction to NOSQL And MongoDBBehrouz Bakhtiari
 
MongoDB World 2019: Using Client Side Encryption in MongoDB 4.2 Link
MongoDB World 2019: Using Client Side Encryption in MongoDB 4.2 LinkMongoDB World 2019: Using Client Side Encryption in MongoDB 4.2 Link
MongoDB World 2019: Using Client Side Encryption in MongoDB 4.2 LinkMongoDB
 
Managing Social Content with MongoDB
Managing Social Content with MongoDBManaging Social Content with MongoDB
Managing Social Content with MongoDBMongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBAlex Bilbie
 
RedisConf17 - Redis as a JSON document store
RedisConf17 - Redis as a JSON document storeRedisConf17 - Redis as a JSON document store
RedisConf17 - Redis as a JSON document storeRedis Labs
 
REST Web API with MongoDB
REST Web API with MongoDBREST Web API with MongoDB
REST Web API with MongoDBMongoDB
 
Kalp Corporate MongoDB Tutorials
Kalp Corporate MongoDB TutorialsKalp Corporate MongoDB Tutorials
Kalp Corporate MongoDB TutorialsKalp Corporate
 
Indexing and Query Optimizer
Indexing and Query OptimizerIndexing and Query Optimizer
Indexing and Query OptimizerMongoDB
 
MongoDB .local London 2019: Using Client Side Encryption in MongoDB 4.2
MongoDB .local London 2019: Using Client Side Encryption in MongoDB 4.2MongoDB .local London 2019: Using Client Side Encryption in MongoDB 4.2
MongoDB .local London 2019: Using Client Side Encryption in MongoDB 4.2Lisa Roth, PMP
 

Similar a One BSON to Rule Them (20)

MongoDB - javascript for your data
MongoDB - javascript for your dataMongoDB - javascript for your data
MongoDB - javascript for your data
 
MongoDB - Javascript for your Data
MongoDB - Javascript for your DataMongoDB - Javascript for your Data
MongoDB - Javascript for your Data
 
Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)
 
MongoDB
MongoDBMongoDB
MongoDB
 
Mongo db Quick Guide
Mongo db Quick GuideMongo db Quick Guide
Mongo db Quick Guide
 
Introduction to NOSQL And MongoDB
Introduction to NOSQL And MongoDBIntroduction to NOSQL And MongoDB
Introduction to NOSQL And MongoDB
 
MongoDB World 2019: Using Client Side Encryption in MongoDB 4.2 Link
MongoDB World 2019: Using Client Side Encryption in MongoDB 4.2 LinkMongoDB World 2019: Using Client Side Encryption in MongoDB 4.2 Link
MongoDB World 2019: Using Client Side Encryption in MongoDB 4.2 Link
 
Managing Social Content with MongoDB
Managing Social Content with MongoDBManaging Social Content with MongoDB
Managing Social Content with MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
RedisConf17 - Redis as a JSON document store
RedisConf17 - Redis as a JSON document storeRedisConf17 - Redis as a JSON document store
RedisConf17 - Redis as a JSON document store
 
Json
JsonJson
Json
 
REST Web API with MongoDB
REST Web API with MongoDBREST Web API with MongoDB
REST Web API with MongoDB
 
Kalp Corporate MongoDB Tutorials
Kalp Corporate MongoDB TutorialsKalp Corporate MongoDB Tutorials
Kalp Corporate MongoDB Tutorials
 
Working with JSON
Working with JSONWorking with JSON
Working with JSON
 
Indexing and Query Optimizer
Indexing and Query OptimizerIndexing and Query Optimizer
Indexing and Query Optimizer
 
MongoDB 101
MongoDB 101MongoDB 101
MongoDB 101
 
Mondodb
MondodbMondodb
Mondodb
 
MongoDB .local London 2019: Using Client Side Encryption in MongoDB 4.2
MongoDB .local London 2019: Using Client Side Encryption in MongoDB 4.2MongoDB .local London 2019: Using Client Side Encryption in MongoDB 4.2
MongoDB .local London 2019: Using Client Side Encryption in MongoDB 4.2
 

Más de David Golden

Slice Recycling Performance and Pitfalls
Slice Recycling Performance and PitfallsSlice Recycling Performance and Pitfalls
Slice Recycling Performance and PitfallsDavid Golden
 
Eversion 101: An Introduction to Inside-Out Objects
Eversion 101: An Introduction to Inside-Out ObjectsEversion 101: An Introduction to Inside-Out Objects
Eversion 101: An Introduction to Inside-Out ObjectsDavid Golden
 
Adventures in Optimization
Adventures in OptimizationAdventures in Optimization
Adventures in OptimizationDavid Golden
 
Make Comments Stand Out
Make Comments Stand OutMake Comments Stand Out
Make Comments Stand OutDavid Golden
 
State of the Velociraptor Mini-Keynote: Perl Toolchain
State of the Velociraptor Mini-Keynote: Perl ToolchainState of the Velociraptor Mini-Keynote: Perl Toolchain
State of the Velociraptor Mini-Keynote: Perl ToolchainDavid Golden
 
Practical Consistency
Practical ConsistencyPractical Consistency
Practical ConsistencyDavid Golden
 
How I get to the ☞
How I get to the ☞How I get to the ☞
How I get to the ☞David Golden
 
Real World Optimization
Real World OptimizationReal World Optimization
Real World OptimizationDavid Golden
 
Safer Chainsaw Juggling (Lightning Talk)
Safer Chainsaw Juggling (Lightning Talk)Safer Chainsaw Juggling (Lightning Talk)
Safer Chainsaw Juggling (Lightning Talk)David Golden
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsDavid Golden
 
Juggling Chainsaws: Perl and MongoDB
Juggling Chainsaws: Perl and MongoDBJuggling Chainsaws: Perl and MongoDB
Juggling Chainsaws: Perl and MongoDBDavid Golden
 
Cooking Perl with Chef: Real World Tutorial with Jitterbug
Cooking Perl with Chef: Real World Tutorial with JitterbugCooking Perl with Chef: Real World Tutorial with Jitterbug
Cooking Perl with Chef: Real World Tutorial with JitterbugDavid Golden
 
Cooking Perl with Chef: Hello World Tutorial
Cooking Perl with Chef: Hello World TutorialCooking Perl with Chef: Hello World Tutorial
Cooking Perl with Chef: Hello World TutorialDavid Golden
 
Cooking Perl with Chef
Cooking Perl with ChefCooking Perl with Chef
Cooking Perl with ChefDavid Golden
 

Más de David Golden (17)

Slice Recycling Performance and Pitfalls
Slice Recycling Performance and PitfallsSlice Recycling Performance and Pitfalls
Slice Recycling Performance and Pitfalls
 
Free QA!
Free QA!Free QA!
Free QA!
 
Eversion 101: An Introduction to Inside-Out Objects
Eversion 101: An Introduction to Inside-Out ObjectsEversion 101: An Introduction to Inside-Out Objects
Eversion 101: An Introduction to Inside-Out Objects
 
Perl 5 Version 13
Perl 5 Version 13Perl 5 Version 13
Perl 5 Version 13
 
IsTrue(true)?
IsTrue(true)?IsTrue(true)?
IsTrue(true)?
 
Adventures in Optimization
Adventures in OptimizationAdventures in Optimization
Adventures in Optimization
 
Make Comments Stand Out
Make Comments Stand OutMake Comments Stand Out
Make Comments Stand Out
 
State of the Velociraptor Mini-Keynote: Perl Toolchain
State of the Velociraptor Mini-Keynote: Perl ToolchainState of the Velociraptor Mini-Keynote: Perl Toolchain
State of the Velociraptor Mini-Keynote: Perl Toolchain
 
Practical Consistency
Practical ConsistencyPractical Consistency
Practical Consistency
 
How I get to the ☞
How I get to the ☞How I get to the ☞
How I get to the ☞
 
Real World Optimization
Real World OptimizationReal World Optimization
Real World Optimization
 
Safer Chainsaw Juggling (Lightning Talk)
Safer Chainsaw Juggling (Lightning Talk)Safer Chainsaw Juggling (Lightning Talk)
Safer Chainsaw Juggling (Lightning Talk)
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order Functions
 
Juggling Chainsaws: Perl and MongoDB
Juggling Chainsaws: Perl and MongoDBJuggling Chainsaws: Perl and MongoDB
Juggling Chainsaws: Perl and MongoDB
 
Cooking Perl with Chef: Real World Tutorial with Jitterbug
Cooking Perl with Chef: Real World Tutorial with JitterbugCooking Perl with Chef: Real World Tutorial with Jitterbug
Cooking Perl with Chef: Real World Tutorial with Jitterbug
 
Cooking Perl with Chef: Hello World Tutorial
Cooking Perl with Chef: Hello World TutorialCooking Perl with Chef: Hello World Tutorial
Cooking Perl with Chef: Hello World Tutorial
 
Cooking Perl with Chef
Cooking Perl with ChefCooking Perl with Chef
Cooking Perl with Chef
 

Último

Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 

Último (20)

Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 

One BSON to Rule Them

  • 1. One BSON
 to RuleThem David Golden Staff Engineer, MongoDB 
 NY Perl Meetup • Dec 2016
  • 2. This talk in a nutshell... https://xkcd.com/927/
  • 9. JSON BSON schema-less schema-less key-value pairs key-value pairs text binary 6 types 21 types unordered ordered
  • 11. JSON BSON document document array array null null string string boolean boolean number int32 int64 float64 (double) decimal128 binary (blob) datetime regular expression javascript code javascript code with data "object id" "minimum key" "maximum key" "timestamp" (3 deprecated types)
  • 14. JSON Perl document hash reference array array reference null undef string string number number boolean ???
  • 15. JSON Perl document hash reference array array reference null undef string string number number boolean ??? Scalar
  • 16. JSON Perl document hash reference array array reference null undef string string number number boolean ??? this way is OK Scalar
  • 17. JSON Perl document hash reference array array reference null undef string string number number boolean ??? this way is NOT OK Scalar
  • 18. use JSON; my $n = 23; say encode_json({n => $n}); # {"n":23}
  • 19. use JSON; my $n = 23; say encode_json({n => $n}); # {"n":23} $n =~ /^d+$/;
  • 20. use JSON; my $n = 23; say encode_json({n => $n}); # {"n":23} $n =~ /^d+$/; say encode_json({n => $n}); # {"n":"23"}
  • 22. JSON Perl document hash reference array array reference null undef string string number number boolean ??? Scalar
  • 23. JSON Perl document hash reference array array reference null undef string string number number boolean ??? Scalar boolean.pm
  • 24. use boolean; my $true = true; my $false = false; say ref $true; # boolean say ref $false # boolean
  • 25. But this is Perl...
  • 27. ...that's why we can't
 have nice things
  • 28. JSON Perl document hash reference array array reference null undef string string number number boolean ??? Scalar boolean.pm
  • 29. JSON Perl document hash reference array array reference null undef string string number number boolean ??? Scalar 0 1 boolean.pm JSON::XS::Boolean JSON::PP::Boolean JSON::Tiny::_Bool Mojo::JSON::_Bool Cpanel::JSON::XS::Boolean Types::Serialiser::Boolean ...
  • 31. BSON Perl document hash reference array array reference null undef string boolean int32 int64 float64 (double) decimal128 binary (blob) datetime regular expression javascript code javascript code with data "object id" "minimum key" "maximum key" "timestamp" (3 deprecated types) Scalar
  • 32. BSON Perl document hash reference array array reference null undef string boolean int32 int64 float64 (double) decimal128 binary (blob) datetime regular expression javascript code javascript code with data "object id" "minimum key" "maximum key" "timestamp" (3 deprecated types) Scalar Lots of wrapper classes
  • 34. Serializing Perl is hard Deserializing typed data is hard
  • 36. Back to my problem... https://xkcd.com/927/
  • 38. MongoDB-v0.x series BSON codec written in XS Heuristics configured via global variables ($MongoDB::BSON::looks_like_number) Wrapper classes boolean.pm, MongoDB::OID, MongoDB::BSON::Binary, MongoDB::Code, ...
  • 39. Goals Provide a pure-Perl option for the Perl driver Get rid of globals and use codec objects Allow users to customize decoding to wrappers
  • 42. Each with their own set of wrapper classes
  • 44. Goals Provide a pure-Perl option for the Perl driver Get rid of globals and use codec objects Allow users to customize decoding to wrappers Provide standard, reusable BSON wrappers
  • 45. We adopted BSON.pm Pure-perl Not widely used (so we can change it more) Lots of wrappers (some with odd APIs) Not tied to Mojolicious ecosystem
  • 47. Step 1. Extract MongoDB BSON to a configurable codec object Define a standard, pluggable codec API (Released with MongoDB-v1.0.0 in mid-2015 )
  • 48. Step 2. Adapt BSON.pm to provide the codec API Adapt or extend wrappers to provide common behaviors needed Prepare BSON.pm for pluggable backends (e.g. future BSON::XS)
 
 (Released to CPAN as BSON-v1.0.0 in July)
  • 49. Step 3. Extract MongoDB XS code to BSON::XS
 
 (Released to CPAN as BSON-XS-v0.2.0 in Oct)
  • 50. Step 4. Remove MongoDB codec from distribution Add dependency on BSON.pm/BSON::XS Make MongoDB wrapper classes into empty subclasses of BSON.pm wrapper classes (Planned for future MongoDB-v2.0.0 in 2017)
  • 54. # MongoDB::OID my $oid1 = MongoDB::OID->new; my $oid2 = MongoDB::OID->new(value => $id1->value); my $oid3 = MongoDB::OID->new($id1->value); my $oid4 = MongoDB::OID->new($id1); # BSON::ObjectID my $oid1 = BSON::ObjectId->new; my $oid2 = BSON::ObjectId->new($string); my $oid3 = BSON::ObjectId->new($binary_string); # Mango::BSON::ObjectID my $oid1 = Mango::BSON::ObjectID->new; my $oid2 = Mango::BSON::ObjectID->new('1a2b3c4e5f60718293a4b5c6');
  • 55. Revised or wrote new BSON.pm wrapper classes Goal: Let all MongoDB::* wrappers become empty subclasses of BSON.pm wrappers - Lots of constructor argument munging - Lots of method name aliasing - Sometimes had to deprecate and start over
  • 57. Scalar Wrapper A Wrapper B Wrapper C Wrapper D Wrapper E Wrapper F BSON bytes Wrapper D Or maybe just scalar
 based on config? Encode Decode
  • 58. Perl type/class -> BSON type -> Perl type/class ------------------------------------------------------------------- float[1] 0x01 DOUBLE float[2] BSON::Double ------------------------------------------------------------------- string[3] 0x02 UTF8 string[2] BSON::String ------------------------------------------------------------------- hashref 0x03 DOCUMENT hashref[4][5] BSON::Doc BSON::Raw MongoDB::BSON::Raw[d] Tie::IxHash ------------------------------------------------------------------- arrayref 0x04 ARRAY arrayref ------------------------------------------------------------------- BSON::Bytes 0x05 BINARY BSON::Bytes scalarref BSON::Binary[d] MongoDB::BSON::Binary[d] ------------------------------------------------------------------- n/a 0x06 UNDEFINED[d] undef ------------------------------------------------------------------- BSON::OID 0x07 OID BSON::OID BSON::ObjectId[d] MongoDB::OID[d] ------------------------------------------------------------------- boolean 0x08 BOOL boolean BSON::Bool[d] JSON::XS::Boolean JSON::PP::Boolean JSON::Tiny::_Bool Mojo::JSON::_Bool Cpanel::JSON::XS::Boolean Types::Serialiser::Boolean ------------------------------------------------------------------- BSON::Time 0x09 DATE_TIME BSON::Time DateTime DateTime::Tiny Time::Moment Mango::BSON::Time ------------------------------------------------------------------- undef 0x0a NULL undef ------------------------------------------------------------------- BSON::Regex 0x0b REGEX BSON::Regex qr// reference MongoDB::BSON::Regexp[d] Perl type/class -> BSON type -> Perl type/class ------------------------------------------------------------------- n/a 0x0c DBPOINTER[d] BSON::DBRef ------------------------------------------------------------------- BSON::Code[6] 0x0d CODE BSON::Code MongoDB::Code[6] ------------------------------------------------------------------- n/a 0x0e SYMBOL[d] string ------------------------------------------------------------------- BSON::Code[6] 0x0f CODEWSCOPE BSON::Code MongoDB::Code[6] ------------------------------------------------------------------- integer[7][8] 0x10 INT32 integer[2] BSON::Int32 ------------------------------------------------------------------- BSON::Timestamp 0x11 TIMESTAMP BSON::Timestamp MongoDB::Timestamp[d] ------------------------------------------------------------------- integer[7] 0x12 INT64 integer[2][9] BSON::Int64 Math::BigInt Math::Int64 ------------------------------------------------------------------- BSON::MaxKey 0x7F MAXKEY BSON::MaxKey MongoDB::MaxKey[d] ------------------------------------------------------------------- BSON::MinKey 0xFF MINKEY BSON::MinKey MongoDB::MinKey[d]
 
 [d] Deprecated or soon to be deprecated. [1] Scalar with "NV" internal representation no "PV" representation, or a string that looks like a float if the 'prefer_numeric' option is true. [2] If the 'wrap_numbers' option is true, numeric types will be wrapped as BSON::Double, BSON::Int32 or BSON::Int64 as appropriate to ensure round-tripping. If the 'wrap_strings' option is true, strings will be wrapped as BSON::String, likewise. [3] Scalar with "PV" representation and not identified as a number by notes [1] or [7]. [4] If 'ordered' option is set, will return a tied hash that preserves order (deprecated 'ixhash' option still works). [5] If the document appears to contain a DBRef and a 'dbref_callback' exists, that callback is executed with the deserialized document. [6] Code is serialized as CODE or CODEWSCOPE depending on whether a scope hashref exists in BSON::Code/MongoDB::Code. [7] Scalar with "IV" internal representation and no "PV" representation, or a string that looks like an integer if the 'prefer_numeric' option is true. [8] Only if the integer fits in 32 bits. [9] On 32-bit platforms, 64-bit integers are deserialized to Math::BigInt objects (even if subsequently wrapped into BSON::Int64 if 'wrap_scalars' is true). From BSON.pm docs
  • 60. Use same tests for both rsync tests from BSON.pm to BSON::XS Tests load t/lib/CleanEnv.pm, which hides either BSON::PP (from BSON.pm) or BSON::XS Ensures both backends consume/produce
 exact same BSON
  • 61. use 5.008001; use strict; use warnings; package CleanEnv; # Tiny equivalent of Devel::Hide to disable BSON::XS use lib map { my ( $m, $c ) = ( $_, qq{die "Can't locate $_ (hidden)n"} ); sub { return unless $_[1] eq $m; open my $fh, "<", $c; return $fh } } qw{BSON/XS.pm}; # Would be BSON/PP.pm for BSON::XS # Keep environment from interfering with tests $ENV{PERL_BSON_BACKEND} = ""; 1; BSON.pm t/lib/CleanEnv.pm
  • 63. Typical Foo/Foo::XS pattern User uses Foo's API Foo delegates to XS methods if Foo::XS loads *foo = has_xs() ? &Foo::XS::_foo : &Foo::_foo; Foo dynamically adds Foo::XS as a dependency if a compiler is detected
  • 64. Our problem & solution BSON::XS tests need BSON.pm wrappers
 Didn't want wrappers as a common prereq 
 Users can check for a compiler and add BSON.pm or BSON::XS (Or perhaps I'll just write BSON::MaybeXS)
  • 66. Lessons learned Serializing needs heuristics and wrapper classes Type mapping is complex and unfun, but needed Common tests for PP/XS are a life-saver
  • 67. Look for MongoDB
 Perl driver v2.0.0
 next year!