renderColRefExpression emits a same-collection column comparison via $expr. Multi-hop belongs-to comparisons are not supported on MongoDB without pre-injecting a $lookup stage in the pipeline, which is outside the scope of the WHERE-clause renderer; reject those at compile time.
(ctx Context, exp *qcode.Exp)
| 3883 | // pre-injecting a $lookup stage in the pipeline, which is outside the scope |
| 3884 | // of the WHERE-clause renderer; reject those at compile time. |
| 3885 | func (d *MongoDBDialect) renderColRefExpression(ctx Context, exp *qcode.Exp) { |
| 3886 | if len(exp.Right.RelPath) > 0 { |
| 3887 | ctx.SetError(fmt.Errorf("mongodb: cross-table column reference operands (multi-hop) are not supported; use a same-collection column reference instead")) |
| 3888 | return |
| 3889 | } |
| 3890 | op, ok := colRefMongoOp(exp.Op) |
| 3891 | if !ok { |
| 3892 | ctx.SetError(fmt.Errorf("mongodb: operator %s does not support column reference operands", exp.Op)) |
| 3893 | return |
| 3894 | } |
| 3895 | leftName := exp.Left.Col.Name |
| 3896 | if leftName == "id" { |
| 3897 | leftName = "_id" |
| 3898 | } |
| 3899 | rightName := exp.Right.Col.Name |
| 3900 | if rightName == "id" { |
| 3901 | rightName = "_id" |
| 3902 | } |
| 3903 | ctx.WriteString(`"$expr":{"`) |
| 3904 | ctx.WriteString(op) |
| 3905 | ctx.WriteString(`":["$`) |
| 3906 | ctx.WriteString(leftName) |
| 3907 | ctx.WriteString(`","$`) |
| 3908 | ctx.WriteString(rightName) |
| 3909 | ctx.WriteString(`"]}`) |
| 3910 | } |
| 3911 | |
| 3912 | func colRefMongoOp(op qcode.ExpOp) (string, bool) { |
| 3913 | switch op { |
no test coverage detected