This repository was archived by the owner on Apr 28, 2024. It is now read-only.
This repository was archived by the owner on Apr 28, 2024. It is now read-only.
Unable to execute Aggregate query with Lookup #68
Open
Description
I tried executing the below query from the IDE and it is panicking. The query works fine in Mongo console and when testing with other IDEs.
db.credits.aggregate([{$lookup:{from: "movies", localField: "id", foreignField: "id", as: "results"}}])
Here is the panic output in console.
2023/01/16 18:32:02 [Recovery] 2023/01/16 - 18:32:02 panic recovered:
POST /api/v1/query/run HTTP/1.1
Host: localhost:22022
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en
Connection: keep-alive
Content-Length: 181
Content-Type: text/json
Origin: http://localhost:3000
Referer: http://localhost:3000/
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-site
Sec-Gpc: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36
runtime error: index out of range [0] with length 0
c:/go/src/runtime/panic.go:89 (0x7ff6e60a5d7e)
goPanicIndex: panic(boundsError{x: int64(x), signed: true, y: y, code: boundsIndex})
X:/Github/slashbase/pkg/queryengines/mongoqueryengine/queryengine.go:280 (0x7ff6e66ce0ae)
(*MongoQueryEngine).RunQuery: Aggregate(context.Background(), queryType.Args[0])
X:/Github/slashbase/pkg/queryengines/queryengines.go:23 (0x7ff6e6b5410e)
RunQuery: return mongoQueryEngine.RunQuery(dbConn, query, config)
X:/Github/slashbase/internal/controllers/query.go:23 (0x7ff6e6ea8607)
QueryController.RunQuery: data, err := queryengines.RunQuery(dbConn.ToQEConnection(), query, getQueryConfigsForProjectMember(dbConn))
X:/Github/slashbase/internal/handlers/query.go:25 (0x7ff6e6eadd44)
QueryHandlers.RunQuery: data, err := queryController.RunQuery(runBody.DBConnectionID, runBody.Query)
C:/Users/prash/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:165 (0x7ff6e6e9c701)
(*Context).Next: c.handlers[c.index](c)
C:/Users/prash/go/pkg/mod/github.com/gin-gonic/[email protected]/recovery.go:99 (0x7ff6e6e9c6ec)
CustomRecoveryWithWriter.func1: c.Next()
C:/Users/prash/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:165 (0x7ff6e6e9b57d)
(*Context).Next: c.handlers[c.index](c)
C:/Users/prash/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:489 (0x7ff6e6e9b205)
(*Engine).handleHTTPRequest: c.Next()
C:/Users/prash/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:445 (0x7ff6e6e9ad64)
(*Engine).ServeHTTP: engine.handleHTTPRequest(c)
c:/go/src/net/http/server.go:2916 (0x7ff6e657bdfa)
serverHandler.ServeHTTP: handler.ServeHTTP(rw, req)
c:/go/src/net/http/server.go:1966 (0x7ff6e6576df6)
(*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)
c:/go/src/runtime/asm_amd64.s:1571 (0x7ff6e60d5a60)
goexit: BYTE $0x90 // NOP
I found the problem to be in this function mongoutils.IsQueryTypeRead(queryType)
where the query.Args
is having 0 elements and therefore panicking. I suppress the panic here but when it gets back in the queryengine
query conditional checks for queryType then it panics there.