Documents and BSON

BSON types, Extended JSON, the comparison order and collation, as in MongoDB.

TeselaDB stores BSON documents with all their types: double, string, document, array, binary, ObjectId, boolean, date, null, regular expression, JavaScript, int, long, Decimal128, Timestamp, MinKey and MaxKey. What your driver writes is what it reads back, byte for byte.

How it works

The document format and the order in which values compare are MongoDB's. They still are when a document travels as JSON through the REST API or mongoexport and when a query compares strings with collation in the language of your data.

Extended JSON

The tools that implement JSON (mongoexport, mongoimport, the REST API) use Extended JSON v2 in its canonical and relaxed modes, with the same rules as MongoDB.

Comparison order

Two values of different types compare by type and then by value, in MongoDB's order: MinKey, null, numbers, strings, documents, arrays, binaries, ObjectId, booleans, dates, Timestamp, regular expressions and MaxKey. Numbers compare by value even when their types differ.

Collation

Text comparisons with collation use the same Unicode data as MongoDB 9.0 (ICU 57.1), so the order and equality of strings in other scripts or with accents and capitals match MongoDB's.

JavaScript
db.customers.find({ surname: "lópez" }).collation({ locale: "es", strength: 1 });

What it means for your application

Your driver stores and reads the same types as with MongoDB. Queries and indexes compare values in the same order as MongoDB, and so do sorts: a sort with collation gives the same result as in MongoDB 9.0.

Limits

  • A string or field name that is not valid UTF-8 is rejected with InvalidBSON (22). MongoDB stores it.
  • A find without sort returns documents in the order of their key within the range, which can differ from insertion order. MongoDB guarantees no order without sort; if your application needs one, ask for it with sort.

Learn more