Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: ed67ce2e96
Fetching contributors…

Cannot retrieve contributors at this time

45 lines (35 sloc) 2.383 kb
Delphi MongoDB Driver
A Delphi driver to access a mongoDB server.
It maps variables onto Delphi variables of type OleVariant, which resembles the loose typing of JavaScript.
There are two main units and three main classes to enable access to a mongo DB server:
TBSONDocument = class(TInterfacedObject, IBSONDocument, IPersistStream)
Holds the data of a 'document', the basic unit of data mongoDB works with.
Implements an IBSONDocument interface which allows it to be referenced by an OleVariant variable, which enables embedding documents.
Implements the IPersistStream interface to enable loading from and saving to BSON, the internal binary storage specification used by mongoDB.
function BSON:IBSONDocument; overload;
function BSON(x:array of OleVariant):IBSONDocument; overload;
Creates a BSON document object ready for use.
Optionally pass a sequence of key-value pairs, e.g.: BSON(['x',5,'y',7]);
Use '[' and ']' to created embedded documents, e.g.: BSON(['x','[','$gt',7,']']);
Use VarArrayOf or 1-dimensional variant arrays to add arrays, e.g.: BSON(['x',VarArrayOf(1,2,3)]);
A connection to a mongoDB server. Supports getting single items, performing inserts, updates and deletes.
A query to a mongoDB server, handles the cursor and subsequent requests to the server to get more data when needed.
Additional tools
function BsonToJson(Doc:IBSONDocument):WideString;
Converts a BSON document into a JSON string.
function JsonToBson(jsonData:WideString):IBSONDocument;
Converts a JSON string into a BSON document.
procedure JsonIntoBson(jsonData:WideString;doc:IBSONDocument); overload;
Parses a JSON string and adds any keys to an existing BSON document, overwriting the value if a key already exists.
procedure JsonIntoBson(jsonData:WideString;doc:IBSONDocument;var EndIndex:integer); overload;
Parses only the first JSON object from a string into an existing BSON document, and returns the index into the string where the JSON object ends.
Use this method to iterate over a list of JSON strings. (See also IBSONDocument.Clear)
Jump to Line
Something went wrong with that request. Please try again.