Skip to content
A MongoDB Aggregation that outputs itself.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


A MongoDB Aggregation that outputs itself.


> var cmd = JSON.parse(cat("mongoquine.json"))
> bsonWoCompare(cmd, db.runCommand(cmd).cursor.firstBatch[0])

mongoquine.json contains the aggregation itself, in command form (ie. parse as JSON and then use db.runCommand()). There should be a single document in the quine collection (can have any contents). The aggregation will return a single document, which can be accessed via the cursor.firstBatch[0] field of the command return. This returned document will be identical to the command document that was sent via runCommand().

quine-tester.js contains a mongo shell test runner to see if a given file is such a quine. It uses (ie. drops) the quine db. Run it as:

mongo --host ... --port ... --eval 'filename = "mongoquine.json"' quine-tester.js

Requires MongoDB 3.4.4 or higher. My understanding is that due to the way $literal works, it's not possible to use this approach without $arrayToObject (which was introduced in version 3.6 and backported to 3.4.4). (Other approaches might be possible; I haven't tried.)

You can’t perform that action at this time.