Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Matlab driver for MongoDB

branch: master
Octocat-spinner-32 .gitignore upgrade to mongo-c-driver 0.7
Octocat-spinner-32 Bson.m Copyright moved to end of source so help works
Octocat-spinner-32 BsonBuffer.m Copyright moved to end of source so help works
Octocat-spinner-32 BsonCodeWScope.m Copyright moved to end of source so help works
Octocat-spinner-32 BsonIterator.m upgrade to mongo-c-driver 0.7
Octocat-spinner-32 BsonOID.m Copyright moved to end of source so help works
Octocat-spinner-32 BsonRegex.m Copyright moved to end of source so help works
Octocat-spinner-32 BsonTimestamp.m Copyright moved to end of source so help works
Octocat-spinner-32 BsonType.m Copyright moved to end of source so help works
Octocat-spinner-32 COPYRIGHT.txt License info added
Octocat-spinner-32 DllMain.c upgrade to mongo-c-driver 0.7
Octocat-spinner-32 GridFS.m Copyright moved to end of source so help works
Octocat-spinner-32 Gridfile.m Copyright moved to end of source so help works
Octocat-spinner-32 GridfileWriter.m Copyright moved to end of source so help works
Octocat-spinner-32 LICENSE.txt License is now Apache 2
Octocat-spinner-32 Mongo.m varargin typos fixed
Octocat-spinner-32 MongoCursor.m Copyright moved to end of source so help works
Octocat-spinner-32 MongoMatlabDriver.h upgrade to mongo-c-driver 0.7
Octocat-spinner-32 MongoMatlabDriver.sln upgrade to mongo-c-driver 0.7
Octocat-spinner-32 MongoMatlabDriver.vcxproj Replica set function name changes
Octocat-spinner-32 MongoMatlabDriver.vcxproj.filters Replica set function name changes
Octocat-spinner-32 MongoMatlabDriver32.dll upgrade to mongo-c-driver 0.7
Octocat-spinner-32 MongoMatlabDriver64.dll upgrade to mongo-c-driver 0.7
Octocat-spinner-32 MongoSample.m MongoSample described
Octocat-spinner-32 MongoStart.m License info added
Octocat-spinner-32 MongoStop.m License info added
Octocat-spinner-32 MongoTest.m Driver Sync; also mongo.distinct() added
Octocat-spinner-32 README.md varargin typos fixed
Octocat-spinner-32 api_bson.c Driver Sync; also mongo.distinct() added
Octocat-spinner-32 api_gridfs.c Replica set function name changes
Octocat-spinner-32 api_mongo.c Replica set function name changes
Octocat-spinner-32 makefile upgrade to mongo-c-driver 0.7
Octocat-spinner-32 mongo-c-driver-src.zip upgrade to mongo-c-driver 0.7
Octocat-spinner-32 substr.m Driver Sync; also mongo.distinct() added
README.md

This is a Matlab extension supporting access to MongoDB.

After cloning this repo, copy the src directory from mongo-c-driver to the main directory of this extension. Alternately, you may unpack mongo-c-driver-src.zip into this directory.

Windows:

Binaries for 64 and 32-bit are provided. Rename MongoMatlabDriver32.dll or MongoMatlabDriver64.dll to MongoMatlabDriver.dll as appropriate.

Building: Load the solution into Visual Studio and build the dll. The project properties may need to be edited to include the locations where the Matlab include files and libs are.

Linux:

~/10gen/mongo-matlab-driver$ make

Note that Matlab requires gcc-4.3


Once the libary is built,

Add the path of the driver to Matlab: > addpath /10gen/mongo-matlab-driver

Then the test suite can be run with: > MongoTest (after changing the current directory to that of this driver)

For normal operation, load the library with: > MongoStart

Documentation may be accessed within Matlab by: > doc Mongo % for instance

though you may find it more convenient to examine the class files directly. Matlab clutters up the help somewhat with documention on methods inherited from 'handle'.

Unload the library with: > MongoStop

(you may have to clear variables in order to do this)

BASIC USAGE:

Connecting to a MongoDB server running on localhost is as straight forward and simple as:

mongo = Mongo();

This creates an instance of the Mongo class which you'll use for subsequent communication with MongoDB. Once you have established the connection, you may execute CRUD operations on the database quite easily. Simplified prototypes for these look like this:

mongo.insert(namespace, record);

result = mongo.findOne(namespace, query);

mongo.update(namespace, criteria, objNew);

mongo.remove(namespace, criteria);

namespace is the name of the collection on which to perform the operation.

A simple example of an actual insert looks like this:

bb = BsonBuffer;

bb.append('name', 'John');

bb.append('age', int32(34));

bb.append('address', '1033 Vine Street');

record = bb.finish();

mongo.insert('test.people', record);

There are 3 convenience functions for storing named values to the collection 'Matlab.vars'. These are: mongo.put('name', value) to store a value with a given name. value = mongo.get('name') to fetch the value associated with a name. mongo.list(); to list the names of the values stored.

If you find these functions handy and useful, you may want to index 'Matlab.vars' by name: mongo.indexCreate('Matlab.vars', 'name')

There is a sample Matlab script which you can run with:

MongoSample

This simple example demonstrates the most common operations of inserting, updating and also the 'usual' query / find loop.

Something went wrong with that request. Please try again.