Neil P
Neil P

Reputation: 3190

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.

Upvotes: 9

Views: 8190

Answers (1)

Andrew Liu
Andrew Liu

Reputation: 8119

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"
}

Upvotes: 17

Related Questions