Cannot use $or or any dollar-sign top level operator in query

Issue #26 new
Anonymous created an issue

We are currently using an old version of Monary (0.2) but are trying to switch to recent versions (0.4 or 0.5). However, after following the instructions and doing a clean install with the latest version of the Mongo C driver, we are unable to use any top-level operator such as $or if mixed with other field. For example, the following query:

{"$or":[{"field1":1},{"field2":2}], "field3":3}

results in:

Cannot mix top-level query with dollar keys such as $orderby. Use {$query: {},...} instead.

If $or is not used, or if field3 is queried alone, the error does not occur. Using $query does not appear to be a true option because it would result in an "unknown operator" error.

To go around this, I modified the Mongo C driver, however we won't be doing such a thing in a live environment since we don't really know why that test is there and what other things we may break. The modification we did was in mongoc-cursor.c - basically we just commented-out lines 419 - 426 here: https://github.com/mongodb/mongo-c-driver/blob/master/src/mongoc/mongoc-cursor.c

The code is very specific to check for mixed dollar-sign and non-dollar sign elements:

     if (_mixed_dollar_non_dollar (query)) {
        bson_set_error (&error,
                        MONGOC_ERROR_CURSOR,
                        MONGOC_ERROR_CURSOR_INVALID_CURSOR,
                        "Cannot mix top-level query with dollar keys such "
                        "as $orderby. Use {$query: {},...} instead.");
        GOTO (done);
     }

Does anyone have any insight about this? Is it a bug? And what needs to be fixed? Is it the C driver or the Monary query builder? And is there a good workaround other than commenting-out the error checking code?

Comments (2)

  1. Log in to comment