Is there any golang package available for building mongodb query from plain logic expression string or URL?

139 views
Skip to first unread message

Ray Yang

unread,
Jun 2, 2017, 7:30:03 PM6/2/17
to golang-nuts
Googled around for a while and found some libs in node.js for the same purpose, e.g.

Is there anything similar available in golang?

Thanks.

DV

unread,
Jun 5, 2017, 8:01:03 PM6/5/17
to golang-nuts
This seems pretty trivial, tbh. You just parse the URL query string and construct a JSON doc out of it?

Go's philosophy in general is that it's better to just write the code yourself sometimes, even multiple times, than to pull in a dependency. Especially for something like this.

Do you remember the Node community's "left-pad" fiasco from last year?

Ray Yang

unread,
Jun 5, 2017, 8:36:51 PM6/5/17
to golang-nuts
Thanks for letting me know that "left-pad" thing. I didn't know it before you mentioned it here.

Parsing a URL string and constructing a BSON object are easy if the criteria is like this:

A.B="foo" AND C.D=true

However, if the query is like this, I'm not sure if it still can be done correctly without careful attention:

((A.B="foo" AND C.D=true) OR E.F="boo" AND G=1234) OR H.I.J IN "abc def xyz"

So what I meant was to target such complex situation which is commonly used in searching large data set. Really appreciate if somebody can point out that there is already something available or even some examples in Go.

Thanks.

Nathan Kerr

unread,
Jun 6, 2017, 2:16:36 AM6/6/17
to golang-nuts
I haven't tried it, but https://github.com/jhsx/qm might be useful.

Ray Yang

unread,
Jun 6, 2017, 2:01:07 PM6/6/17
to golang-nuts
Thanks Nathan. It has builder part but I need both parser and builder.

It looks that I have to build the wheel or at least part of it.
Reply all
Reply to author
Forward
0 new messages