Skip to content
A C shared lib along with associated q functions to allow push/pull access to mongoDB from within kdb+
C
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
LICENSE
README.md
k.h
mongo.q
mongoc.h
mongoq.c
mongoq.def

README.md

mongoq

About

A C shared lib along with associated q functions to allow push/pull access to mongoDB from within kdb+

Installation

  • Install the mongo c driver libraries | repo | instructions
  • Clone the mongoq git repo
  • Compile shared object using platform specific instructions below
Linux (64 bit)
gcc -o mongoq.so mongoq.c $(pkg-config --cflags --libs libmongoc-1.0) -I./ -shared -fPIC
Windows
CL /DWIN32 /I C:\usr\include\libbson-1.0 /I C:\usr\include\libmongoc-1.0 /LIBPATH C:\usr\lib\bson-1.0.lib /LIBPATH C:\usr\lib\mongoc-1.0.lib /LD mongoq.c q.lib /DEF mongoq.def
  • copy the shared library file from the bin folder to the location of your q executable - e.g. $QHOME/l32
  • copy mongo.q to $QHOME

Usage

Load and initialise library

This assumes there is a MongoDB server running on the local machine on the standard port - amend the connection details as required for your MongoDB setup

\l mongo.q
.mg.init[`localhost;27017;`kdb]

Insert data to MongoDB

q).mg.add[`test] `a`b`c!(1;`xyz;12t) / single record
00000000-54ef-b9bd-dfa8-32369e099741
q)r:.mg.add[`test] ([]time:3 4t;sym:`IBM`MSFT;price:23.4 56.7) / table

Query data from MongoDB

The '.mg.add' function returns a 16 byte UID type, which maps to the MongoDB ObjectID key of the inserted record. We can use these ids to retrieve data:

q).mg.find[`test;;()] r / all fields for id(s) r in table 'test'
time           sym    price
---------------------------
"03:00:00.000" "IBM"  23.4
"04:00:00.000" "MSFT" 56.7
q).mg.find[`test;;`sym`price] r / only sym & price fields
sym    price
------------
"IBM"  23.4
"MSFT" 56.7

Examples

You can’t perform that action at this time.