All Projects → OpenKitten → Bson

OpenKitten / Bson

Licence: mit
Native Swift library for BSON (http://bsonspec.org)

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Bson

Mongo Cxx Driver
C++ Driver for MongoDB
Stars: ✭ 792 (+854.22%)
Mutual labels:  bson, mongodb
Kafka Connect Mongodb
**Unofficial / Community** Kafka Connect MongoDB Sink Connector - Find the official MongoDB Kafka Connector here: https://www.mongodb.com/kafka-connector
Stars: ✭ 137 (+65.06%)
Mutual labels:  bson, mongodb
Lua Mongo
MongoDB Driver for Lua
Stars: ✭ 81 (-2.41%)
Mutual labels:  bson, mongodb
Objcmongodb
Mac OS and iOS library for MongoDB and BSON
Stars: ✭ 166 (+100%)
Mutual labels:  bson, mongodb
Bson4jackson
A pluggable BSON generator and parser for the Jackson JSON processor.
Stars: ✭ 244 (+193.98%)
Mutual labels:  bson, mongodb
Mgodatagen
Generate random data for MongoDB
Stars: ✭ 206 (+148.19%)
Mutual labels:  bson, mongodb
Mongo Kafka
MongoDB Kafka Connector
Stars: ✭ 166 (+100%)
Mutual labels:  bson, mongodb
Lungo
A MongoDB compatible embeddable database and toolkit for Go.
Stars: ✭ 343 (+313.25%)
Mutual labels:  bson, mongodb
Avocado
Strongly-typed MongoDB driver for Rust
Stars: ✭ 70 (-15.66%)
Mutual labels:  bson, mongodb
Runner
Start all mongodb deployment types for testing
Stars: ✭ 78 (-6.02%)
Mutual labels:  mongodb
Mern
🎉 This is boilerplate for MERN stack with integrations like Redux and SSR 🎉
Stars: ✭ 77 (-7.23%)
Mutual labels:  mongodb
Polled.win
📊 Real time polling
Stars: ✭ 76 (-8.43%)
Mutual labels:  mongodb
Cheatsheets
JavaScript and Node.js cheatsheets
Stars: ✭ 1,191 (+1334.94%)
Mutual labels:  mongodb
Mongo Xlsx
Convert Mongo data into Excel and vice versa @ Node.js. MongoDB Mongoose Dump to excel.
Stars: ✭ 81 (-2.41%)
Mutual labels:  mongodb
Koa Ts
koa2+typescript
Stars: ✭ 82 (-1.2%)
Mutual labels:  mongodb
Node Oauth2 Server Mongo Example
Working oauth2 server with mongodb storage and minimal configuration
Stars: ✭ 76 (-8.43%)
Mutual labels:  mongodb
Aus Search
A collection of Node JS scripts to create an Elasticsearch index of Australian addresses.
Stars: ✭ 76 (-8.43%)
Mutual labels:  mongodb
Nodejs Imgshare
A social App using Nodejs and Javascript technologies to Share Images
Stars: ✭ 83 (+0%)
Mutual labels:  mongodb
Authenticationintro
Stars: ✭ 82 (-1.2%)
Mutual labels:  mongodb
Koa2 Ratelimit
Rate-limiting middleware for Koa2 ES6. Use to limit repeated requests to APIs and/or endpoints such as password reset.
Stars: ✭ 81 (-2.41%)
Mutual labels:  mongodb

BSON

Swift 4.2 Swift 5.3 License Build Status

BSON 7 is a fast BSON library. It's compliant to the whole BSON specification test suite. The library parses the binary data on-demand, delaying copies until the last second.

BSON is parsed and generated as specified for version 1.1 of the BSON specification.

Installation

BSIN uses the Swift Package Manager. Add MongoKitten to your dependencies in your Package.swift file:

.package(url: "https://github.com/OpenKitten/BSON.git", from: "7.0.0")

Also, don't forget to add "BSON" as a dependency for your target.

Basic Usage

Create Documents using Dictionary Literals:

var userDocument: Document = [
	"username": "Joannis",
	"online": true,
	"age": 20,
	"pi_constant": 3.14,
	"profile": [
		"firstName": "Joannis",
		"lastName": "Orlandos"
	]
]

let favouriteNumbers: Document = [1, 3, 7, 14, 21, 24, 34]

userDocument["favouriteNumbers"] = favouriteNumbers

Access values in an array like you would in Swift Arrays and values in an object like a Dictionary.

let favouriteNumber = favouriteNumbers[0]
let usernameValue = userDocument["username"]

Extract types with simplicity:

let username = String(userDocument["username"]) // "Joannis"
let isOnline = Bool(userDocument["online"]) // true
let age = Int(userDocument["age"]) // 20
let pi = Double(userDocument["pi_constant"]) // 3.14

Chain subscripts easily to find results without a hassle as shown underneath using this JSON structure (assuming this is represented in BSON):

{
  "users": [
  	{
  		"username": "Joannis",
  		"profile": {
  		  "firstName": "Joannis",
  		  "lastName": "Orlandos"
  		}
  	},
  	{
  		"username": "Obbut",
  		"profile": {
  		  "firstName": "Robbert",
  		  "lastName": "Brandsma"
  		}
  	}
  ]
}
let obbutLastName = String(object["users"][1]["profile"]["lastName"]) // "Brandsma"

Nested Documents

Complex array and dictionary literals may confuse the Swift type system. If this happens to you, make the literal explicitly a Document type:

var userDocument: Document = [
	"username": "Joannis",
	"online": true,
	"age": 20,
	"pi_constant": 3.14,
	"profile": [
		"firstName": "Joannis",
		"lastName": "Orlandos",
		"pets": [
			[
				"name": "Noodles",
				"type": "Parrot"
			] as Document,
			[
				"name": "Witje",
				"type": "Rabbit"
			]
		] as Document
	] as Document
]

Codable

Document can be instantiated from SwiftNIO's ByteBuffer or Foundation.Data. You can validate the formatting of this document manually using the .validate() function. This will also specify where the data was found corrupt.

If you pass a Document or Primitive into the BSONDecoder you can decode any Decodable type if the formats match. Likewise, BSONEncoder can encode your Swift types into a Document.

Supported Types

All non-deprecated BSON 1.1 types are supported.

  • Double
  • String
  • Document
  • Array
  • ObjectId
  • Bool
  • DateTime
  • 32-bit integer
  • 64-bit integer
  • Null value
  • Binary
  • Regular Expression
  • Min Key
  • Max Key
  • Timestamp
  • Javascript Code
  • Javascript Code with Scope
  • Decimal128
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].