From b8273b364a0e4f6ddab0dddd683385a64f14ff74 Mon Sep 17 00:00:00 2001 From: Joannis Orlandos Date: Tue, 2 Jan 2018 14:55:24 +0100 Subject: [PATCH] Basic BSON docs --- 3.0/docs/databases/mongodb/bson.md | 56 ++++++++++++++++++++++++++++++ 3.0/mkdocs.yml | 1 + 2 files changed, 57 insertions(+) diff --git a/3.0/docs/databases/mongodb/bson.md b/3.0/docs/databases/mongodb/bson.md index e69de29b..6959ed68 100644 --- a/3.0/docs/databases/mongodb/bson.md +++ b/3.0/docs/databases/mongodb/bson.md @@ -0,0 +1,56 @@ +# BSON + +BSON is a performant (not compact) format for storing data in MongoDB. +The BSON module used here is extremely performant and support Codable. + +## Primitives + +MongoDB has a set of supported primitives. At the root of any BSON data lies a `Document`. + +- Double +- String +- Document (Array and Dictionary) +- ObjectId +- Bool +- Int32 +- Int (Int64) +- Binary +- Decimal128 **(not supported)** +- JavascriptCode +- Null (not nil) +- Date (from Foundation) +- MinKey +- MaxKey +- RegularExpression (BSON Type) + +### Document + +Document is a type that comes in two representations. Array and Dictionary-like. +You should see Document as `[(String, Primitive)]`. + +Array-like Documents ignore the key (`String`) whilst Dictionary-like Documents require using it. +For this reason, both `Document` variants are the same struct type and behave the same way. + +You can subscript a dictionary-like document with an integer, and an array-like document by it's key. + +## Usage + +The root type of any BSON structure is a `Document`, please note that MongoDB entities **must** be a dictionary-like. + +To create a dictionary-like BSON Document: + +```swift +// Dictionary document by default +var document = Document() +``` + +You can also use a dictionary or array literal. This creates the respective BSON document type. + +```swift +var arrayDocument: Document = [] +var dictionaryDocument: Document = [:] +``` + + + +## Codable diff --git a/3.0/mkdocs.yml b/3.0/mkdocs.yml index b4f2b487..fd9e7085 100644 --- a/3.0/mkdocs.yml +++ b/3.0/mkdocs.yml @@ -59,6 +59,7 @@ pages: - 'Databases': - 'MongoDB': - 'Getting Started': 'databases/mongodb/getting-started.md' + - 'BSON': 'databases/mongodb/bson.md' - 'Basics': 'databases/mongodb/basics.md' - 'Interpreting tutorials': 'databases/mongodb/interpreting.md' - 'MySQL':