I've created a database and a collection. When creating the collection, the partition key was a required field and the hint suggested that '/id' would be a good choice so I used that.
Now I'm trying to query the database following the instructions here. The sample code provided does not include a partition key but when I do a query following that example, I get the following error: The partition key supplied in x-ms-partitionkey header has fewer components than defined in the the collection.
Note first that this error message is itself wrong. the missing header is x-ms-documentdb-partitionkey
.
Next, when I add a header with a partition key, I get a new error: The input content is invalid because the required properties - 'id; ' - are missing.
If I add an 'id' to the body then I get a new error: Entity with the specified id already exists in the system.
Here is a portion of my Dart code:
var url ='https://${client.account}.documents.azure.com/dbs/$databaseName/colls/$_projects/docs';
var uri = Uri.parse(url);
var headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': '*',
'Accept': 'application/json',
'Content-Type': 'application/query+json',
'Authorization': 'type=aad&ver=1.0&sig=${token['access_token']}',
'x-ms-date': DateTime.now().asRfc1123(),
'x-ms-version': '2018-12-31',
'x-ms-documentdb-isquery': 'True',
'x-ms-documentdb-query-enablecrosspartition': 'True',
};
var body = {
'query':
'SELECT p.id, p.name FROM Projects p',
'parameters': [],
};
var response;
try {
response = await http.post(uri, headers: headers, body: jsonEncode(body));
} catch (e) {
print(e.toString());
}
print(response.statusCode);
print(jsonDecode(response.body));
Why does a cross-partition query require a partition key? What value should I give for the partition key if the partition key is one of the fields I don't know and want returned?
I want a list of names from the database. Is that too much to ask?