How to add a new operator to the aggregation framework

80 views
Skip to first unread message

Estanislao Oubel

unread,
Feb 5, 2016, 12:36:27 PM2/5/16
to mongodb-user

Hello all,


I would like to add new functions into the aggregation framework, and I have started trying to reproduce Elliot's work (http://www.eliothorowitz.com/blog/2015/07/09/extending-the-aggregation-framework/). However, this is not working yet ... This is what I did:


1. I have cloned the mongodb project available in github (https://github.com/mongodb/mongo)
2. I have successfully compiled mongod.exe by using scons
3. I have cloned the "$inject" projet (https://gist.github.com/erh/957e3193b9bd79b16cb1) into C:\mongo\src\mongo\db\957e3193b9bd79b16cb1 (I don't have a directory C:\mongo\src\mongo\db\modules as mentioned in the post)
4. I have added "957e3193b9bd79b16cb1" to the list of directories in C:\mongo\src\mongo\db\SConscript
5. I have recompiled mongod.exe


However, when I do db.zipcodes.aggregate({ $inject : "funField" }); in a mongo shell I get the following error:


2016-02-03T11:19:30.983+0100 E QUERY Error: command failed:

{ "ok" : 0, "errmsg" : "Unrecognized pipeline stage name: '$inject'", "code" : 16436 }

: aggregate failed
at Error (<anonymous>)
at doassert (src/mongo/shell/assert.js:11:14)
at Function.assert.commandWorked (src/mongo/shell/assert.js:254:5)
at DBCollection.aggregate (src/mongo/shell/collection.js:1278:12)
at (shell):1:13 at src/mongo/shell/assert.js:13


Could you please tell me what I'm doing wrong? Am I forgetting something?


Stan

Wan Bachtiar

unread,
Feb 16, 2016, 11:34:05 PM2/16/16
to mongodb-user

Could you please tell me what I’m doing wrong? Am I forgetting something?

Hi Stan,

For step number three, first create a directory called modules in src/mongo/db/. Afterward, clone the gist repo into the src/mongo/db/modules/ and rename it to something sensible. For example you could rename the gist directory to inject.

Another thing to note is that the SConscript has changed since the blog post. You would need to modify the inject’s SConscript to look like below:

# -*- mode: python -*-
Import("env")

env.Library(target='inject',
            source=['inject.cpp'],
            LIBDEPS=['$BUILD_DIR/mongo/base'],
            LIBDEPS_DEPENDENTS=['$BUILD_DIR/mongo/db/pipeline/pipeline'])

Lastly rebuild MongoDB. See Build MongoDB From Source for more information on building MongoDB.

This was tested on :

  • MongoDB master. Currently is at git version 3125749c23f8cf341768ecc37c86e64a2c30a356.
  • MongoDB branch v3.2
  • MongoDB tag r3.2.1.

Note that this question is perhaps more suited for mongodb-dev where you may get a wider audience for the development of MongoDB.

Regards,

Wan.

Estanislao Oubel

unread,
Feb 17, 2016, 3:29:16 AM2/17/16
to mongodb-user
Hello Wan,

Thanks a lot, it is working now.

Best

Stan
Reply all
Reply to author
Forward
0 new messages