Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query sub array #12

Open
kaliazur opened this issue Aug 21, 2018 · 1 comment
Open

Query sub array #12

kaliazur opened this issue Aug 21, 2018 · 1 comment

Comments

@kaliazur
Copy link

kaliazur commented Aug 21, 2018

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 !

@pavelsmejkal
Copy link
Collaborator

Isn't it just because of you misunderstand PartitionKey option ? Try to set reqOpts.PartitionKey to real value. I believe it should contain value that will be used for partition number calculation. Not a path to value since you are not providing it in request. Docdb gateway can decide which partition it should use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants