Query sub array
- 主要語言
- Go
- 星號
- 31
- 分支
- 26
- PR 合併指標
- 30 天內沒有已合併 PR
描述
Hi !
I am trying to execute a query on a subdocument and I didn't manage to make it work .....
My CosmosDB documents are like that:
```
{
[...]
"references": [
{
"id": "1234",
"link": "http://site.com/1234"
},
{
"id": "5678",
"link": "http://site.com/5678"
}
]
```
The query I tried is this one: `SELECT * FROM r WHERE ARRAY_CONTAINS(r.references, {id:'1234'}, true)`
( note that the third 'true' parameter to ARRAY_CONTAINS() is to say "the provided object is incomplete" )
With this request, I have this error:
```panic: BadRequest, Cross partition query is required but disabled. Please set x-ms-documentdb-query-enablecrosspartition to true, specify x-ms-documentdb-partitionkey, or revise your query to avoid this exception.```
Next I tried to use QueryDocument with Partition like that:
```
partitionKey := func(reqOpts *documentdb.RequestOptions) {
reqOpts.PartitionKey = []string{"/internal_id"}
}
query := fmt.Sprintf("SELECT * FROM r WHERE ARRAY_CONTAINS(r.references, {id:'1234'}, true)")
var ObjFound []Obj
err = client.QueryDocumentsWithRequestOptions(coll.Self, query, &ObjFound, partitionKey)
if err != nil {
panic(err)
}
```
With that, I don't have any error, but I am not finding any documents ...
Moreover, this request works fine in the Azure Data Explorer from the web interface.
Did someone manage to make that kind of request work ?
Thank you !
貢獻指南
這個儲存庫沒有索引到貢獻指南
研究方向
The issue is about querying subdocuments in CosmosDB using the Go driver. The user's query with ARRAY_CONTAINS fails with a cross-partition error or returns no results. Start by examining the QueryDocumentsWithRequestOptions method and how partition keys are handled. Check the driver's query execution logic and compare it with the working Azure Data Explorer query. Look for any discrepancies in query formatting or partition key specification.
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- azure, go
- 領域
- backend, databases
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 30/100