Is there a way to see the equivalent mongo console command?

40 views
Skip to first unread message

Justin Hellings

unread,
Apr 4, 2017, 12:02:53 PM4/4/17
to mgo-users
I'm just starting to use the mongo aggregation pipeline using mgo.Pipe. I am doing something wrong with regards to and $and operator.

I have set a logger and set debug in mgo and can see the debug output. The debug output shows a dump of the go data structure that I passed to Collection.Pipe()

Is there a way to see what I would have to type in the Mongo console to have the same affect? Either the whole command, or just the pipeline stages data structure? That would really help with debugging.

I tried editing the pipeline stage that I had defined in go by hand for use in the mongo console, but I didn't get an error when I used it there. I think I may be using the wrong mgo classes to represent the components of my pipeline stages.

I'll submit my specific error here for help if necessary, but I wondered whether there was a general solution for debugging this.

Justin Hellings

unread,
Apr 5, 2017, 8:06:42 AM4/5/17
to mgo-users
Just a note to say that I've solved the immediate problem. (I was confused about the different use of $and in a query object and $and in the options for some pipeline stages.)

I would still be interested in knowing about any general way of debugging these problems. Is a manually editing the go data structure for use in the Mongo console the way to go? Is it just that bson.M is a bson object and bson.D is an array of bson objects and []interface{} is a polymorphic array?

Justin Hellings

unread,
Apr 5, 2017, 11:24:24 AM4/5/17
to mgo-users
I found docs about profiling settings in mongo. I think I might have already seen references to these but dismissed them as not what I was looking for because I had been focussed on the word "logging". This is what I did:

    db.setProfilingLevel(2)
   
// Then ran a mongo command through my app.
    db
.system.profile.find()

I inspected the profiling for a use of mgo.Pipe. I could see the pipeline stages data structure as it would be entered in the Mongo console. This let me easily cut-and-paste it into a command in the console. Problem solved.

Once you have a few kinds of entry in the system.profile collection, it may be useful to filter them to find what you want, e.g.

    db.system.profile.find({"ns":"myDbName.MyCollectionName"}).pretty()



(I guess "ns" stands for namespace.)

Reply all
Reply to author
Forward
0 new messages