Mongo Dbsource

Introduction #

SmartChart supports MongoDB as a data source, reading data from MongoDB collections via JSON format query configuration. Since MongoDB returns dict format, you typically need to use ds_mapToList() in the chart to convert to SmartChart standard 2D array format.


Usage #

Configure the connection pool normally. In the dataset editor, write query configuration:

Screenshot

{"db": "db1", "table": "tb1", "filter": {"name": "Zarten"},
"projection": {"_id": 0}, "sort": [["_id", 1]], "limit": 10}

Since the return is dict format, convert to 2D array using:

let dataset = ds_mapToList(__dataset__);

Parameter Description #

Except table, all parameters are optional

Parameter Description Example
db Database name, defaults to connection db
table Collection name [required]
filter Filter criteria {“name”: “Zarten”,“date”:“2020-10-01”}
projection Display fields {“name”: 1,“date”:1}
sort Sort, -1 for descending [[“date”, -1]]
limit Limit return count

Filter Conditions #

AND condition:

{"age": {"$gt": 22}, "name": {"$regex": "user"}}

OR condition:

{"$or": [{"age": {"$gt": 22}}, {"name": {"$regex": "user"}}]}

Comparison: $lt = <, $lte = <=, $gt = >, $gte = >=, $ne = !=

{"field_name": {"$lt": value, "$gt": value}}

$in and $nin:

{"field_name": {"$in": [1, 5, 8]}}

$regex for fuzzy matching:

{"$or": [{"field_name": {"$regex": value}}, {"field_name2": {"$regex": value}}]}