Client Side Document Matching
Basic Document Matching

The MongoDB C driver supports matching a subset of the MongoDB query specification on the client.

Currently, basic numeric and string equality, $gt, $gte, $lt, $lte, $in, $nin, $ne, $exists, $type are supported. As this is not the same implemenation as the MongoDB server, some inconsitencies may occur. Please file a bug if you find such a case.

The following example performs a basic query against a BSON document.

example-matcher.c

The following example shows how to process a BSON stream from stdin and match it against a query. This can be useful if you need to perform simple matching against mongodump backups.

filter-bsondump.c

To test this, perform a mongodump of a single collection and pipe it to the program.

$ echo "db.test.insert({hello:'world'})" | mongo MongoDB shell version: 2.6.1 connecting to: test WriteResult({ "nInserted" : 1 }) bye $ mongodump -d test -c test -o - | filter-bsondump { "_id" : { "$oid" : "537afac9a70e5b4d556153bc" }, "hello" : "world" }