getredash/redash · error · Exception
$oids takes an array as input.
Error message
$oids takes an array as input.
What it means
parse_oids() is used by the MongoDB query runner's JSON deserializer to expand "$oid" constructs in queries (writing ObjectIds as JSON). It requires its input to be a JSON array of ObjectId hex strings; anything else is rejected. This is the error path for {"$oid": ...}-style documents built incorrectly.
Source
Thrown at redash/query_runner/mongodb.py:50
enabled = False
TYPES_MAP = {
str: TYPE_STRING,
bytes: TYPE_STRING,
int: TYPE_INTEGER,
float: TYPE_FLOAT,
bool: TYPE_BOOLEAN,
datetime.datetime: TYPE_DATETIME,
}
date_regex = re.compile(r'ISODate\("(.*)"\)', re.IGNORECASE)
def parse_oids(oids):
if not isinstance(oids, list):
raise Exception("$oids takes an array as input.")
return [bson_object_hook({"$oid": oid}) for oid in oids]
def datetime_parser(dct):
for k, v in dct.items():
if isinstance(v, str):
m = date_regex.findall(v)
if len(m) > 0:
dct[k] = parse(m[0], yearfirst=True)
if "$humanTime" in dct:
return parse_human_time(dct["$humanTime"])
if "$oids" in dct:
return parse_oids(dct["$oids"])
opts = JSONOptions(tz_aware=True)View on GitHub (pinned to ca79fe988d)
Solutions
- Ensure the $oids value is a JSON array: {"$oid": {"$oids": ["hex1", "hex2"]}}
- For a single ObjectId use {"$oid": "<24-char hex>"} directly instead of $oids
- Regenerate the extended JSON with a proper bson/json_util serializer
Example fix
// before
{"_id": {"$oid": {"$oids": "507f1f77bcf86cd799439011"}}}
// after
{"_id": {"$oid": "507f1f77bcf86cd799439011"}} Defensive patterns
Strategy: type-guard
Type guard
def as_oid_array(v):
assert isinstance(v, list) and all(isinstance(o, str) and len(o) == 24 for o in v), 'oids must be array of 24-hex strings'
return v Try / catch
try:
run_mongodb_query(q)
except Exception as e:
if '$oids takes an array' in str(e):
q = fix_extended_json_oids(q) # wrap ids in a list, use $oid for single id Prevention
- Use bson.json_util to serialize ObjectIds instead of hand-writing $oid/$oids
- Single id: {"$oid": hex}; multiple: {"$oids": [hex, ...]}
When it happens
Trigger: A query contains {"$oid": {"$oids": "5f1a..."}} or passes an object/string where an array is expected, e.g. "$oids": {"0": "abc"} instead of "$oids": ["abc"].
Common situations: Converting an ObjectId to JSON with a custom encoder that emits $oid/$oids but wrapping multiple ids in a dict instead of a list; hand-writing extended JSON that doesn't follow the array shape.
Related errors
- MongoDB connection error
- Invalid JWT token
- Error during query execution. Reason: {error}
- Failed running query [%s].
- Username and Password required
AI-assisted analysis of getredash/redash@ca79fe988d (2026-08-28).
Data as JSON: /api/errors/7ffa369bb0c3cc1e.
Report an issue: GitHub.