SlideShare ist ein Scribd-Unternehmen logo
1 von 89
Downloaden Sie, um offline zu lesen
Application Design
FOR MongoDB
Alessandro Palumbo
apalumbo@byte-code.com
http:/
/it.linkedin.com/in/alessandropalumbo/
http:/
/www.byte-code.com

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

MongoDB

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

MongoDB
NoSql

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

MongoDB
NoSql
OPEN-source

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

MongoDB
NoSql
OPEN-source
Document-Oriented
JSON-style documents

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

MongoDB
NoSql
OPEN-source
Document-Oriented
JSON-style documents
from humongous
“huge; enormous”
Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

JSON-style
documents
{
"_id" : "6c85fa4c-fa64-44e2-89c9-e5eb7f306ed7",
"code" : "CRS0001",
"name" : "Test",
"description" : "Test description",
"active" : true,
"scheduledDate" : {
"from" : ISODate("2013-09-12T00:00:00.000Z"),
"to" : ISODate("2013-10-31T00:00:00.000Z")
},
"version" : NumberLong(1)
}

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

don’t be relationaL

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

don’t be relationaL
no joins

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

don’t be relationaL
no joins

NO FULL
transactions

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

don’t be relationaL
no joins

NO FULL
transactions
no SCHEMA
Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

don’t be relationaL
no joins

WE CAN EMBED

NO FULL
transactions
no SCHEMA
Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

don’t be relationaL
no joins

WE CAN EMBED

NO FULL
transactions

DOCUMENT LEVEL
TRANSACTIONS

no SCHEMA
Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

don’t be relationaL
no joins

WE CAN EMBED

NO FULL
transactions
no SCHEMA

DOCUMENT LEVEL
TRANSACTIONS
IS IT REALLY
AN ISSUE?

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

friendly fire
(aka RTFM)
ATOMIC
DOCUMENT
OPERATIONS

Write
Concern

READ
PREFERENCE

AVOID
NATURAL
KEYS AS
IDENTIFIERS

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

friendly fire

DESIGN

(aka RTFM)
ATOMIC
DOCUMENT
OPERATIONS

Write
Concern

READ
PREFERENCE

AVOID
NATURAL
KEYS AS
IDENTIFIERS

DESIGN
FOR
QUERY

DBREFS
VS
MANUAL
REFERENCE

DYNAMIC
SCHEMA
VS
static
languages

EMBEDDED
DATA
vs
References

BE
CAREFUL
WITH
DATES

SPLIT DATA
ON
MULTIPLE
COLLECTIONS

PURE DRIVER
VS
MAPPING
FRAMEWORKS

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

friendly fire

DESIGN

PERFORMANCE

(aka RTFM)
ATOMIC
DOCUMENT
OPERATIONS

Write
Concern

READ
PREFERENCE

AVOID
NATURAL
KEYS AS
IDENTIFIERS

DESIGN
FOR
QUERY

DBREFS
VS
MANUAL
REFERENCE

DYNAMIC
SCHEMA
VS
static
languages

EMBEDDED
DATA
vs
References

be aware
of
the trees

BE
CAREFUL
WITH
DATES

PREALLOCATE
FIELDS?

SPLIT DATA
ON
MULTIPLE
COLLECTIONS

TUNING
UPDATES
AND
INSERTS

PURE DRIVER
VS
MAPPING
FRAMEWORKS

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,

DOCUMENT
MOVING
SLOWS
YOU

PREPROCESS
HIGH
RESOLUTION
DATA
FRIENDLY FIRE

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

ATOMIC
DOCUMENT
OPERATIONS

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

ATOMIC
DOCUMENT
OPERATIONS

OPERATIONS ON MULTIPLE DOCUMENTS
ARE NOT ATOMIC

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

ATOMIC
DOCUMENT
OPERATIONS

OPERATIONS ON MULTIPLE DOCUMENTS
ARE NOT ATOMIC
NO “ALL OR NOTHING”

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

ATOMIC
DOCUMENT
OPERATIONS

OPERATIONS ON MULTIPLE DOCUMENTS
ARE NOT ATOMIC
NO “ALL OR NOTHING”
EMBEDding OR APPLIcaTION TRANSACTIONS
CAN be used to handle the issue

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

ATOMIC
DOCUMENT
OPERATIONS

OPERATIONS ON MULTIPLE DOCUMENTS
ARE NOT ATOMIC
NO “ALL OR NOTHING”
EMBEDding OR APPLIcaTION TRANSACTIONS
CAN be used to handle the issue
RELATIONAL TRANSACTIONS ARE NOT
TOTALLY SAFE
Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

Write
Concern

“Describes the guarantee that
MongoDB provides when reporting
on the success of a write
operation”

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

Write
Concern

“Describes the guarantee that
MongoDB provides when reporting
on the success of a write
operation”

IT IS SET BY THE CLIENT AND CAN BE SET FOR
EACH OPERATION

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

Write
Concern

“Describes the guarantee that
MongoDB provides when reporting
on the success of a write
operation”

IT IS SET BY THE CLIENT AND CAN BE SET FOR
EACH OPERATION
Errors Ignored

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

Write
Concern

“Describes the guarantee that
MongoDB provides when reporting
on the success of a write
operation”

IT IS SET BY THE CLIENT AND CAN BE SET FOR
EACH OPERATION
Errors Ignored

Unacknowledged

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

Write
Concern

“Describes the guarantee that
MongoDB provides when reporting
on the success of a write
operation”

IT IS SET BY THE CLIENT AND CAN BE SET FOR
EACH OPERATION
Errors Ignored

Unacknowledged

Acknowledged (*)

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

Write
Concern

“Describes the guarantee that
MongoDB provides when reporting
on the success of a write
operation”

IT IS SET BY THE CLIENT AND CAN BE SET FOR
EACH OPERATION
Errors Ignored

Unacknowledged

Acknowledged (*)

Journaled

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

Write
Concern

“Describes the guarantee that
MongoDB provides when reporting
on the success of a write
operation”

IT IS SET BY THE CLIENT AND CAN BE SET FOR
EACH OPERATION
Errors Ignored

Unacknowledged

Acknowledged (*)

Journaled

Replica Acknowledged
> 1 , majority , custom using tags
Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

Read
Preference

“IT describes how MongoDB clients
route read operations to members
of a replica set”

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

Read
Preference

“IT describes how MongoDB clients
route read operations to members
of a replica set”

IT IS SET BY THE CLIENT AND CAN BE SET FOR
EACH OPERATION

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

Read
Preference

“IT describes how MongoDB clients
route read operations to members
of a replica set”

IT IS SET BY THE CLIENT AND CAN BE SET FOR
EACH OPERATION

primary (*)

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

Read
Preference

“IT describes how MongoDB clients
route read operations to members
of a replica set”

IT IS SET BY THE CLIENT AND CAN BE SET FOR
EACH OPERATION

primary (*)

primary Preferred

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

Read
Preference

“IT describes how MongoDB clients
route read operations to members
of a replica set”

IT IS SET BY THE CLIENT AND CAN BE SET FOR
EACH OPERATION

primary (*)

primary Preferred

secondary

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

Read
Preference

“IT describes how MongoDB clients
route read operations to members
of a replica set”

IT IS SET BY THE CLIENT AND CAN BE SET FOR
EACH OPERATION

primary (*)

primary Preferred

secondary

secondary PREFERRED

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

Read
Preference

“IT describes how MongoDB clients
route read operations to members
of a replica set”

IT IS SET BY THE CLIENT AND CAN BE SET FOR
EACH OPERATION

primary (*)

primary Preferred

secondary

secondary PREFERRED

nearest
Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

AVOID
NATURAL
KEYS AS
IDENTIFIERS

All collections have an index on
the id field that exists by default.
If ID IS NOT PROVIDED the driver or
the mongod will create an _id
field with an ObjectID value.

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

AVOID
NATURAL
KEYS AS
IDENTIFIERS

All collections have an index on
the id field that exists by default.
If ID IS NOT PROVIDED the driver or
the mongod will create an _id
field with an ObjectID value.

ADD AN UNIQUE INDEX ON THE NATURAL KEY,
SOMETIMES THE APPLICATION REALM CAN
EVOLVE IN AN UNEXPECTED WAY

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

AVOID
NATURAL
KEYS AS
IDENTIFIERS

All collections have an index on
the id field that exists by default.
If ID IS NOT PROVIDED the driver or
the mongod will create an _id
field with an ObjectID value.

ADD AN UNIQUE INDEX ON THE NATURAL KEY,
SOMETIMES THE APPLICATION REALM CAN
EVOLVE IN AN UNEXPECTED WAY
REMEMBER THAT UNIQUE INDEXES FIELDS
MUST BE PART OF THE SHARD KEY IF
SHARDING IS ENABLED
Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
DESIGN

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

DESIGN
FOR
QUERY

DOCUMENT DESIGN IS FUNCTIONAL TO
THE QUERIES THAT WILL EXISTS IN THE
APPLICATION

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

DESIGN
FOR
QUERY

DOCUMENT DESIGN IS FUNCTIONAL TO
THE QUERIES THAT WILL EXISTS IN THE
APPLICATION

REFERENCE OR EMBED DOCUMENTS,
“denormalized” is not always
a bad word

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

DESIGN
FOR
QUERY

DOCUMENT DESIGN IS FUNCTIONAL TO
THE QUERIES THAT WILL EXISTS IN THE
APPLICATION

REFERENCE OR EMBED DOCUMENTS,
“denormalized” is not always
a bad word
your document design will affect
what kind of OPERATIONS will be safe
or not
Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

EMBEDDED
DATA
vs
References

Embedded data models allow
applications to store related
pieces of information in the same
database record

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

EMBEDDED
DATA
vs
References

Embedded data models allow
applications to store related
pieces of information in the same
database record

USUALLY there is a “contains” relation
between the embedding and the embedded
object

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

EMBEDDED
DATA
vs
References

Embedded data models allow
applications to store related
pieces of information in the same
database record

USUALLY there is a “contains” relation
between the embedding and the embedded
object
The maximum BSON document size is 16
megabytes and embedding may lead to
performance issues if not correctly used
Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

EMBEDDED
DATA
vs
References

Normalized data models describe
relationships using references
between documents

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

EMBEDDED
DATA
vs
References

Normalized data models describe
relationships using references
between documents

References provides more flexibility
than embedding but remember that
client-side applications will have to
lookup for referenced objects with
multiple queries

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

EMBEDDED
DATA
vs
References

Normalized data models describe
relationships using references
between documents

References provides more flexibility
than embedding but remember that
client-side applications will have to
lookup for referenced objects with
multiple queries
NO Referential integrity is supported,
references could point to a not existing
object
Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

DBREFS
VS
MANUAL
REFERENCE

DBRefs are a convention for
representing a document, it will
hold the collection name, the id,
and optionally the db name

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

DBREFS
VS
MANUAL
REFERENCE

DBRefs are a convention for
representing a document, it will
hold the collection name, the id,
and optionally the db name

MANUAL REFERENCES are just fields
that will hold the id of the
related document, without the
collection name or the db name

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

DBREFS
VS
MANUAL
REFERENCE

DBRefs are a convention for
representing a document, it will
hold the collection name, the id,
and optionally the db name

MANUAL REFERENCES are just fields
that will hold the id of the
related document, without the
collection name or the db name
MANUAL REFERENCES are suitable
for most of the use cases
Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

BE
CAREFUL
WITH
DATES

ALWAYS Use bson date when is
related to an instant of time or
you will never be able to use
operators on that fields

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

BE
CAREFUL
WITH
DATES

ALWAYS Use bson date when is
related to an instant of time or
you will never be able to use
operators on that fields

BSON Date is a 64-bit signed integer
that represents the number of
milliseconds since the Unix epoch
(Jan 1, 1970), Negative values
represent dates before 1970.
The official BSON specification
refers to the BSON Date type as
the UTC datetime.
Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

SPLIT DATA
ON
MULTIPLE
COLLECTIONS

split data on multiple collections
to easily partition your data
(a.k.a. Multitenancy)

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

SPLIT DATA
ON
MULTIPLE
COLLECTIONS

split data on multiple collections
to easily partition your data
(a.k.a. Multitenancy)

use collections as namespaces for
your data

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

SPLIT DATA
ON
MULTIPLE
COLLECTIONS

split data on multiple collections
to easily partition your data
(a.k.a. Multitenancy)

use collections as namespaces for
your data
remember once data is partioned it
will be more hard to aggregate if
needed

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

DYNAMIC
SCHEMA
VS
static
languages

why use dynamic schema if we are
not using a dynamic programming
language?

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

DYNAMIC
SCHEMA
VS
static
languages

why use dynamic schema if we are
not using a dynamic programming
language?

inheritance is not only a matter
of hierarchy, it could be also a
matter of composition

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

DYNAMIC
SCHEMA
VS
static
languages

why use dynamic schema if we are
not using a dynamic programming
language?

inheritance is not only a matter
of hierarchy, it could be also a
matter of composition
composition is the key to
introduce dynamic schema in a
static programming language

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

PURE DRIVER
VS
MAPPING
FRAMEWORKS

using the mongo driver directly
will give you great powers, but
will force you to write a lot of
boilerplate code

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

PURE DRIVER
VS
MAPPING
FRAMEWORKS

using the mongo driver directly
will give you great powers, but
will force you to write a lot of
boilerplate code

MAPPING FRAMEWORKS WILL HELP TO
WRITE LESS CODE, but you will sacrifice
the control on all the aspects of the
persistence

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

PURE DRIVER
VS
MAPPING
FRAMEWORKS

using the mongo driver directly
will give you great powers, but
will force you to write a lot of
boilerplate code

MAPPING FRAMEWORKS WILL HELP TO
WRITE LESS CODE, but you will sacrifice
the control on all the aspects of the
persistence

why not take the most from both?
Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
PERFORMANCE

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

be aware
of
the trees

Indexes in MongoDB are defined at
the collection level and can be on
any field or sub-field of the
document

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

be aware
of
the trees

Indexes in MongoDB are defined at
the collection level and can be on
any field or sub-field of the
document

Indexes are created using a b-tree and can
be of different types

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

be aware
of
the trees

Indexes in MongoDB are defined at
the collection level and can be on
any field or sub-field of the
document

Indexes are created using a b-tree and can
be of different types
Single Field

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

be aware
of
the trees

Indexes in MongoDB are defined at
the collection level and can be on
any field or sub-field of the
document

Indexes are created using a b-tree and can
be of different types
Single Field

Compound

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

be aware
of
the trees

Indexes in MongoDB are defined at
the collection level and can be on
any field or sub-field of the
document

Indexes are created using a b-tree and can
be of different types
Single Field

Compound

Multikey

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

be aware
of
the trees

Indexes in MongoDB are defined at
the collection level and can be on
any field or sub-field of the
document

Indexes are created using a b-tree and can
be of different types
Single Field

Compound

Multikey

Geospatial

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

be aware
of
the trees

Indexes in MongoDB are defined at
the collection level and can be on
any field or sub-field of the
document

Indexes are created using a b-tree and can
be of different types
Single Field

Compound

Multikey

Geospatial

TEXT (BETA)

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

be aware
of
the trees

Indexes in MongoDB are defined at
the collection level and can be on
any field or sub-field of the
document

Indexes are created using a b-tree and can
be of different types
Single Field

Compound

Multikey

Geospatial

TEXT (BETA)

Hashed

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

be aware
of
the trees

Indexes in MongoDB are defined at
the collection level and can be on
any field or sub-field of the
document

Indexes are created using a b-tree and can
be of different types
Single Field

Compound

Multikey

Geospatial

TEXT (BETA)

Hashed

THEY COULD BE UNIQUE and sparse
Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

DOCUMENT
MOVING
SLOWS
YOU

MONGODB handle the space
allocation of a RECORD
considering also a PADDING FACTOR

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

DOCUMENT
MOVING
SLOWS
YOU

MONGODB handle the space
allocation of a RECORD
considering also a PADDING FACTOR

WHEN AN UPDATED DOCUMENT DOES
NOT FIT IN THE RECORD SPACE IT WILL
BE MOVED

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

DOCUMENT
MOVING
SLOWS
YOU

MONGODB handle the space
allocation of a RECORD
considering also a PADDING FACTOR

WHEN AN UPDATED DOCUMENT DOES
NOT FIT IN THE RECORD SPACE IT WILL
BE MOVED
DYNAMIC SCHEMA IS THE FIRST CAUSE
OF DOCUMENT MOVING

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

PREALLOCATE
FIELDS?

FIELDS PREALLOCATION CAN FIX THE
DOCUMENT MOVING ISSUES IN SOME USE
CASES

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

PREALLOCATE
FIELDS?

FIELDS PREALLOCATION CAN FIX THE
DOCUMENT MOVING ISSUES IN SOME USE
CASES

Default values must be used to
preallocate, this MUST BE HANDLEDin the
application

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

PREALLOCATE
FIELDS?

FIELDS PREALLOCATION CAN FIX THE
DOCUMENT MOVING ISSUES IN SOME USE
CASES

Default values must be used to
preallocate, this MUST BE HANDLEDin the
application
NULL is not a default value :-) as it has
its own type

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

PREPROCESS
HIGH
RESOLUTION
DATA

MONGODB let you store the
maximum resolution of your data

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

PREPROCESS
HIGH
RESOLUTION
DATA

MONGODB let you store the
maximum resolution of your data

MAP REDUCE and aggregation ARE ok
but you could also preprocess and
have aggregated data that you can
use for your queries

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

PREPROCESS
HIGH
RESOLUTION
DATA

MONGODB let you store the
maximum resolution of your data

MAP REDUCE and aggregation ARE ok
but you could also preprocess and
have aggregated data that you can
use for your queries

MONGODB rocks for business
intelligence

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

TUNING
UPDATES
AND
INSERTS

MongoDB stores BSON documents
as a sequence of fields and values,
not as aN hash table

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

TUNING
UPDATES
AND
INSERTS

MongoDB stores BSON documents
as a sequence of fields and values,
not as aN hash table

WRITING THE FIRST FIELD OF A DOCUMENT (OR
A NESTED DOCUMENT) is considerably
faster than writing THE LAST

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Alessandro Palumbo - apalumbo@byte-code.com - http:/
/www.byte-code.com

TUNING
UPDATES
AND
INSERTS

MongoDB stores BSON documents
as a sequence of fields and values,
not as aN hash table

WRITING THE FIRST FIELD OF A DOCUMENT (OR
A NESTED DOCUMENT) is considerably
faster than writing THE LAST

Intra-Document Hierarchy could help to
handle the issue

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Any questions?

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,
Any questions?

Except where otherwise noted, this work is licensed under: http:/
/creativecommons.org/licenses/by/3.0/

Saturday, November 30,

Weitere ähnliche Inhalte

Mehr von Codemotion

Pompili - From hero to_zero: The FatalNoise neverending story
Pompili - From hero to_zero: The FatalNoise neverending storyPompili - From hero to_zero: The FatalNoise neverending story
Pompili - From hero to_zero: The FatalNoise neverending storyCodemotion
 
Pastore - Commodore 65 - La storia
Pastore - Commodore 65 - La storiaPastore - Commodore 65 - La storia
Pastore - Commodore 65 - La storiaCodemotion
 
Pennisi - Essere Richard Altwasser
Pennisi - Essere Richard AltwasserPennisi - Essere Richard Altwasser
Pennisi - Essere Richard AltwasserCodemotion
 
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...Codemotion
 
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019Codemotion
 
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019Codemotion
 
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 - Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 - Codemotion
 
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...Codemotion
 
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...Codemotion
 
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...Codemotion
 
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...Codemotion
 
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019Codemotion
 
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019Codemotion
 
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019Codemotion
 
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...Codemotion
 
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...Codemotion
 
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019Codemotion
 
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019Codemotion
 
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019Codemotion
 
Mike Kotsur - What can philosophy teach us about programming - Codemotion Ams...
Mike Kotsur - What can philosophy teach us about programming - Codemotion Ams...Mike Kotsur - What can philosophy teach us about programming - Codemotion Ams...
Mike Kotsur - What can philosophy teach us about programming - Codemotion Ams...Codemotion
 

Mehr von Codemotion (20)

Pompili - From hero to_zero: The FatalNoise neverending story
Pompili - From hero to_zero: The FatalNoise neverending storyPompili - From hero to_zero: The FatalNoise neverending story
Pompili - From hero to_zero: The FatalNoise neverending story
 
Pastore - Commodore 65 - La storia
Pastore - Commodore 65 - La storiaPastore - Commodore 65 - La storia
Pastore - Commodore 65 - La storia
 
Pennisi - Essere Richard Altwasser
Pennisi - Essere Richard AltwasserPennisi - Essere Richard Altwasser
Pennisi - Essere Richard Altwasser
 
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
 
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
 
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
 
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 - Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
 
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
 
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
 
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
 
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
 
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
 
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
 
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
 
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
 
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
 
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
 
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
 
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
 
Mike Kotsur - What can philosophy teach us about programming - Codemotion Ams...
Mike Kotsur - What can philosophy teach us about programming - Codemotion Ams...Mike Kotsur - What can philosophy teach us about programming - Codemotion Ams...
Mike Kotsur - What can philosophy teach us about programming - Codemotion Ams...
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 

Kürzlich hochgeladen (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 

Application Design per MongoDB

  • 1. Application Design FOR MongoDB Alessandro Palumbo apalumbo@byte-code.com http:/ /it.linkedin.com/in/alessandropalumbo/ http:/ /www.byte-code.com Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 2. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com MongoDB Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 3. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com MongoDB NoSql Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 4. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com MongoDB NoSql OPEN-source Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 5. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com MongoDB NoSql OPEN-source Document-Oriented JSON-style documents Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 6. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com MongoDB NoSql OPEN-source Document-Oriented JSON-style documents from humongous “huge; enormous” Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 7. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com JSON-style documents { "_id" : "6c85fa4c-fa64-44e2-89c9-e5eb7f306ed7", "code" : "CRS0001", "name" : "Test", "description" : "Test description", "active" : true, "scheduledDate" : { "from" : ISODate("2013-09-12T00:00:00.000Z"), "to" : ISODate("2013-10-31T00:00:00.000Z") }, "version" : NumberLong(1) } Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 8. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com don’t be relationaL Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 9. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com don’t be relationaL no joins Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 10. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com don’t be relationaL no joins NO FULL transactions Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 11. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com don’t be relationaL no joins NO FULL transactions no SCHEMA Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 12. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com don’t be relationaL no joins WE CAN EMBED NO FULL transactions no SCHEMA Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 13. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com don’t be relationaL no joins WE CAN EMBED NO FULL transactions DOCUMENT LEVEL TRANSACTIONS no SCHEMA Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 14. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com don’t be relationaL no joins WE CAN EMBED NO FULL transactions no SCHEMA DOCUMENT LEVEL TRANSACTIONS IS IT REALLY AN ISSUE? Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 15. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 16. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com friendly fire (aka RTFM) ATOMIC DOCUMENT OPERATIONS Write Concern READ PREFERENCE AVOID NATURAL KEYS AS IDENTIFIERS Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 17. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com friendly fire DESIGN (aka RTFM) ATOMIC DOCUMENT OPERATIONS Write Concern READ PREFERENCE AVOID NATURAL KEYS AS IDENTIFIERS DESIGN FOR QUERY DBREFS VS MANUAL REFERENCE DYNAMIC SCHEMA VS static languages EMBEDDED DATA vs References BE CAREFUL WITH DATES SPLIT DATA ON MULTIPLE COLLECTIONS PURE DRIVER VS MAPPING FRAMEWORKS Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 18. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com friendly fire DESIGN PERFORMANCE (aka RTFM) ATOMIC DOCUMENT OPERATIONS Write Concern READ PREFERENCE AVOID NATURAL KEYS AS IDENTIFIERS DESIGN FOR QUERY DBREFS VS MANUAL REFERENCE DYNAMIC SCHEMA VS static languages EMBEDDED DATA vs References be aware of the trees BE CAREFUL WITH DATES PREALLOCATE FIELDS? SPLIT DATA ON MULTIPLE COLLECTIONS TUNING UPDATES AND INSERTS PURE DRIVER VS MAPPING FRAMEWORKS Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30, DOCUMENT MOVING SLOWS YOU PREPROCESS HIGH RESOLUTION DATA
  • 19. FRIENDLY FIRE Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 20. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com ATOMIC DOCUMENT OPERATIONS Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 21. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com ATOMIC DOCUMENT OPERATIONS OPERATIONS ON MULTIPLE DOCUMENTS ARE NOT ATOMIC Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 22. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com ATOMIC DOCUMENT OPERATIONS OPERATIONS ON MULTIPLE DOCUMENTS ARE NOT ATOMIC NO “ALL OR NOTHING” Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 23. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com ATOMIC DOCUMENT OPERATIONS OPERATIONS ON MULTIPLE DOCUMENTS ARE NOT ATOMIC NO “ALL OR NOTHING” EMBEDding OR APPLIcaTION TRANSACTIONS CAN be used to handle the issue Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 24. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com ATOMIC DOCUMENT OPERATIONS OPERATIONS ON MULTIPLE DOCUMENTS ARE NOT ATOMIC NO “ALL OR NOTHING” EMBEDding OR APPLIcaTION TRANSACTIONS CAN be used to handle the issue RELATIONAL TRANSACTIONS ARE NOT TOTALLY SAFE Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 25. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com Write Concern “Describes the guarantee that MongoDB provides when reporting on the success of a write operation” Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 26. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com Write Concern “Describes the guarantee that MongoDB provides when reporting on the success of a write operation” IT IS SET BY THE CLIENT AND CAN BE SET FOR EACH OPERATION Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 27. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com Write Concern “Describes the guarantee that MongoDB provides when reporting on the success of a write operation” IT IS SET BY THE CLIENT AND CAN BE SET FOR EACH OPERATION Errors Ignored Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 28. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com Write Concern “Describes the guarantee that MongoDB provides when reporting on the success of a write operation” IT IS SET BY THE CLIENT AND CAN BE SET FOR EACH OPERATION Errors Ignored Unacknowledged Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 29. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com Write Concern “Describes the guarantee that MongoDB provides when reporting on the success of a write operation” IT IS SET BY THE CLIENT AND CAN BE SET FOR EACH OPERATION Errors Ignored Unacknowledged Acknowledged (*) Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 30. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com Write Concern “Describes the guarantee that MongoDB provides when reporting on the success of a write operation” IT IS SET BY THE CLIENT AND CAN BE SET FOR EACH OPERATION Errors Ignored Unacknowledged Acknowledged (*) Journaled Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 31. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com Write Concern “Describes the guarantee that MongoDB provides when reporting on the success of a write operation” IT IS SET BY THE CLIENT AND CAN BE SET FOR EACH OPERATION Errors Ignored Unacknowledged Acknowledged (*) Journaled Replica Acknowledged > 1 , majority , custom using tags Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 32. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com Read Preference “IT describes how MongoDB clients route read operations to members of a replica set” Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 33. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com Read Preference “IT describes how MongoDB clients route read operations to members of a replica set” IT IS SET BY THE CLIENT AND CAN BE SET FOR EACH OPERATION Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 34. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com Read Preference “IT describes how MongoDB clients route read operations to members of a replica set” IT IS SET BY THE CLIENT AND CAN BE SET FOR EACH OPERATION primary (*) Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 35. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com Read Preference “IT describes how MongoDB clients route read operations to members of a replica set” IT IS SET BY THE CLIENT AND CAN BE SET FOR EACH OPERATION primary (*) primary Preferred Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 36. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com Read Preference “IT describes how MongoDB clients route read operations to members of a replica set” IT IS SET BY THE CLIENT AND CAN BE SET FOR EACH OPERATION primary (*) primary Preferred secondary Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 37. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com Read Preference “IT describes how MongoDB clients route read operations to members of a replica set” IT IS SET BY THE CLIENT AND CAN BE SET FOR EACH OPERATION primary (*) primary Preferred secondary secondary PREFERRED Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 38. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com Read Preference “IT describes how MongoDB clients route read operations to members of a replica set” IT IS SET BY THE CLIENT AND CAN BE SET FOR EACH OPERATION primary (*) primary Preferred secondary secondary PREFERRED nearest Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 39. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com AVOID NATURAL KEYS AS IDENTIFIERS All collections have an index on the id field that exists by default. If ID IS NOT PROVIDED the driver or the mongod will create an _id field with an ObjectID value. Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 40. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com AVOID NATURAL KEYS AS IDENTIFIERS All collections have an index on the id field that exists by default. If ID IS NOT PROVIDED the driver or the mongod will create an _id field with an ObjectID value. ADD AN UNIQUE INDEX ON THE NATURAL KEY, SOMETIMES THE APPLICATION REALM CAN EVOLVE IN AN UNEXPECTED WAY Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 41. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com AVOID NATURAL KEYS AS IDENTIFIERS All collections have an index on the id field that exists by default. If ID IS NOT PROVIDED the driver or the mongod will create an _id field with an ObjectID value. ADD AN UNIQUE INDEX ON THE NATURAL KEY, SOMETIMES THE APPLICATION REALM CAN EVOLVE IN AN UNEXPECTED WAY REMEMBER THAT UNIQUE INDEXES FIELDS MUST BE PART OF THE SHARD KEY IF SHARDING IS ENABLED Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 42. DESIGN Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 43. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com DESIGN FOR QUERY DOCUMENT DESIGN IS FUNCTIONAL TO THE QUERIES THAT WILL EXISTS IN THE APPLICATION Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 44. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com DESIGN FOR QUERY DOCUMENT DESIGN IS FUNCTIONAL TO THE QUERIES THAT WILL EXISTS IN THE APPLICATION REFERENCE OR EMBED DOCUMENTS, “denormalized” is not always a bad word Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 45. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com DESIGN FOR QUERY DOCUMENT DESIGN IS FUNCTIONAL TO THE QUERIES THAT WILL EXISTS IN THE APPLICATION REFERENCE OR EMBED DOCUMENTS, “denormalized” is not always a bad word your document design will affect what kind of OPERATIONS will be safe or not Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 46. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com EMBEDDED DATA vs References Embedded data models allow applications to store related pieces of information in the same database record Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 47. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com EMBEDDED DATA vs References Embedded data models allow applications to store related pieces of information in the same database record USUALLY there is a “contains” relation between the embedding and the embedded object Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 48. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com EMBEDDED DATA vs References Embedded data models allow applications to store related pieces of information in the same database record USUALLY there is a “contains” relation between the embedding and the embedded object The maximum BSON document size is 16 megabytes and embedding may lead to performance issues if not correctly used Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 49. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com EMBEDDED DATA vs References Normalized data models describe relationships using references between documents Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 50. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com EMBEDDED DATA vs References Normalized data models describe relationships using references between documents References provides more flexibility than embedding but remember that client-side applications will have to lookup for referenced objects with multiple queries Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 51. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com EMBEDDED DATA vs References Normalized data models describe relationships using references between documents References provides more flexibility than embedding but remember that client-side applications will have to lookup for referenced objects with multiple queries NO Referential integrity is supported, references could point to a not existing object Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 52. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com DBREFS VS MANUAL REFERENCE DBRefs are a convention for representing a document, it will hold the collection name, the id, and optionally the db name Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 53. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com DBREFS VS MANUAL REFERENCE DBRefs are a convention for representing a document, it will hold the collection name, the id, and optionally the db name MANUAL REFERENCES are just fields that will hold the id of the related document, without the collection name or the db name Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 54. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com DBREFS VS MANUAL REFERENCE DBRefs are a convention for representing a document, it will hold the collection name, the id, and optionally the db name MANUAL REFERENCES are just fields that will hold the id of the related document, without the collection name or the db name MANUAL REFERENCES are suitable for most of the use cases Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 55. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com BE CAREFUL WITH DATES ALWAYS Use bson date when is related to an instant of time or you will never be able to use operators on that fields Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 56. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com BE CAREFUL WITH DATES ALWAYS Use bson date when is related to an instant of time or you will never be able to use operators on that fields BSON Date is a 64-bit signed integer that represents the number of milliseconds since the Unix epoch (Jan 1, 1970), Negative values represent dates before 1970. The official BSON specification refers to the BSON Date type as the UTC datetime. Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 57. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com SPLIT DATA ON MULTIPLE COLLECTIONS split data on multiple collections to easily partition your data (a.k.a. Multitenancy) Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 58. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com SPLIT DATA ON MULTIPLE COLLECTIONS split data on multiple collections to easily partition your data (a.k.a. Multitenancy) use collections as namespaces for your data Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 59. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com SPLIT DATA ON MULTIPLE COLLECTIONS split data on multiple collections to easily partition your data (a.k.a. Multitenancy) use collections as namespaces for your data remember once data is partioned it will be more hard to aggregate if needed Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 60. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com DYNAMIC SCHEMA VS static languages why use dynamic schema if we are not using a dynamic programming language? Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 61. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com DYNAMIC SCHEMA VS static languages why use dynamic schema if we are not using a dynamic programming language? inheritance is not only a matter of hierarchy, it could be also a matter of composition Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 62. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com DYNAMIC SCHEMA VS static languages why use dynamic schema if we are not using a dynamic programming language? inheritance is not only a matter of hierarchy, it could be also a matter of composition composition is the key to introduce dynamic schema in a static programming language Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 63. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com PURE DRIVER VS MAPPING FRAMEWORKS using the mongo driver directly will give you great powers, but will force you to write a lot of boilerplate code Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 64. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com PURE DRIVER VS MAPPING FRAMEWORKS using the mongo driver directly will give you great powers, but will force you to write a lot of boilerplate code MAPPING FRAMEWORKS WILL HELP TO WRITE LESS CODE, but you will sacrifice the control on all the aspects of the persistence Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 65. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com PURE DRIVER VS MAPPING FRAMEWORKS using the mongo driver directly will give you great powers, but will force you to write a lot of boilerplate code MAPPING FRAMEWORKS WILL HELP TO WRITE LESS CODE, but you will sacrifice the control on all the aspects of the persistence why not take the most from both? Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 66. PERFORMANCE Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 67. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com be aware of the trees Indexes in MongoDB are defined at the collection level and can be on any field or sub-field of the document Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 68. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com be aware of the trees Indexes in MongoDB are defined at the collection level and can be on any field or sub-field of the document Indexes are created using a b-tree and can be of different types Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 69. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com be aware of the trees Indexes in MongoDB are defined at the collection level and can be on any field or sub-field of the document Indexes are created using a b-tree and can be of different types Single Field Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 70. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com be aware of the trees Indexes in MongoDB are defined at the collection level and can be on any field or sub-field of the document Indexes are created using a b-tree and can be of different types Single Field Compound Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 71. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com be aware of the trees Indexes in MongoDB are defined at the collection level and can be on any field or sub-field of the document Indexes are created using a b-tree and can be of different types Single Field Compound Multikey Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 72. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com be aware of the trees Indexes in MongoDB are defined at the collection level and can be on any field or sub-field of the document Indexes are created using a b-tree and can be of different types Single Field Compound Multikey Geospatial Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 73. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com be aware of the trees Indexes in MongoDB are defined at the collection level and can be on any field or sub-field of the document Indexes are created using a b-tree and can be of different types Single Field Compound Multikey Geospatial TEXT (BETA) Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 74. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com be aware of the trees Indexes in MongoDB are defined at the collection level and can be on any field or sub-field of the document Indexes are created using a b-tree and can be of different types Single Field Compound Multikey Geospatial TEXT (BETA) Hashed Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 75. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com be aware of the trees Indexes in MongoDB are defined at the collection level and can be on any field or sub-field of the document Indexes are created using a b-tree and can be of different types Single Field Compound Multikey Geospatial TEXT (BETA) Hashed THEY COULD BE UNIQUE and sparse Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 76. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com DOCUMENT MOVING SLOWS YOU MONGODB handle the space allocation of a RECORD considering also a PADDING FACTOR Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 77. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com DOCUMENT MOVING SLOWS YOU MONGODB handle the space allocation of a RECORD considering also a PADDING FACTOR WHEN AN UPDATED DOCUMENT DOES NOT FIT IN THE RECORD SPACE IT WILL BE MOVED Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 78. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com DOCUMENT MOVING SLOWS YOU MONGODB handle the space allocation of a RECORD considering also a PADDING FACTOR WHEN AN UPDATED DOCUMENT DOES NOT FIT IN THE RECORD SPACE IT WILL BE MOVED DYNAMIC SCHEMA IS THE FIRST CAUSE OF DOCUMENT MOVING Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 79. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com PREALLOCATE FIELDS? FIELDS PREALLOCATION CAN FIX THE DOCUMENT MOVING ISSUES IN SOME USE CASES Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 80. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com PREALLOCATE FIELDS? FIELDS PREALLOCATION CAN FIX THE DOCUMENT MOVING ISSUES IN SOME USE CASES Default values must be used to preallocate, this MUST BE HANDLEDin the application Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 81. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com PREALLOCATE FIELDS? FIELDS PREALLOCATION CAN FIX THE DOCUMENT MOVING ISSUES IN SOME USE CASES Default values must be used to preallocate, this MUST BE HANDLEDin the application NULL is not a default value :-) as it has its own type Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 82. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com PREPROCESS HIGH RESOLUTION DATA MONGODB let you store the maximum resolution of your data Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 83. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com PREPROCESS HIGH RESOLUTION DATA MONGODB let you store the maximum resolution of your data MAP REDUCE and aggregation ARE ok but you could also preprocess and have aggregated data that you can use for your queries Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 84. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com PREPROCESS HIGH RESOLUTION DATA MONGODB let you store the maximum resolution of your data MAP REDUCE and aggregation ARE ok but you could also preprocess and have aggregated data that you can use for your queries MONGODB rocks for business intelligence Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 85. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com TUNING UPDATES AND INSERTS MongoDB stores BSON documents as a sequence of fields and values, not as aN hash table Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 86. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com TUNING UPDATES AND INSERTS MongoDB stores BSON documents as a sequence of fields and values, not as aN hash table WRITING THE FIRST FIELD OF A DOCUMENT (OR A NESTED DOCUMENT) is considerably faster than writing THE LAST Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 87. Alessandro Palumbo - apalumbo@byte-code.com - http:/ /www.byte-code.com TUNING UPDATES AND INSERTS MongoDB stores BSON documents as a sequence of fields and values, not as aN hash table WRITING THE FIRST FIELD OF A DOCUMENT (OR A NESTED DOCUMENT) is considerably faster than writing THE LAST Intra-Document Hierarchy could help to handle the issue Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 88. Any questions? Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,
  • 89. Any questions? Except where otherwise noted, this work is licensed under: http:/ /creativecommons.org/licenses/by/3.0/ Saturday, November 30,