Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DocumentDB - The input name is invalid. Ensure to provide a unique non-empty string less than '255' characters

I am trying to insert data into Azure DocumentDb, however I am getting the following error

The input name "123456" is invalid. Ensure to provide a unique non-empty string less than '255' characters.","The request payload is invalid. Ensure to provide a valid request payload."]}

I am using the following code:

using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(myString)))
                {
                    await client.CreateDocumentAsync(documentCollection.DocumentsLink, Document.LoadFrom<Document>(ms));
                }

This code appears to be correct, however I have also tried using the docomentCollection.SelfLink and that also fails.

The database and collection have been created and I can verify this through the azure portal, however no data is ever inserted.

like image 414
Neil P Avatar asked Sep 21 '15 17:09

Neil P


1 Answers

DocumentDB treats id as a special property, in which it must be a unique non-empty string with less than 255 characters.

In this case, I believe you are creating a document with the id as a numeric value:

{
  "id": 123456
}

You will need to cast the id to a string:

{
  "id": "123456"
}
like image 161
Andrew Liu Avatar answered Oct 13 '22 00:10

Andrew Liu