I'm migrating an application from Azure SQL DB to Cosmos DB and am having trouble storing documents in CosmosDB.
My application is written in C# using the Microsoft.Azure.DocumentDB library. When I use the method CreateDocumentAsync(Uri, object) from the library Microsoft.Azure.DocumentDB to insert a record it goes throught without any error. When I query the database using the Azure CosmosDB Data explorer I do not see any records although in the mongo shell the count() states the records are there and the .find() gives an error "Unknown server error occurred when processing this request."
I used the library Microsoft.Azure.DocumentDB to make a crud of sorts. I tested it with the emulator wich worked. however when I was trying to couple a online cosmosDB I came upon the problem that the moment that I insert a document via the method CreateDocumentAsync(Uri, object) from the library I no longer am able to see inserted documents in the comosDb dataexplorer.
I tried to insert it without an id and tried to insert it with a objectId _id however I kept getting the same problem.
When I look in the collection via the mongo shell I do see that a document has been added but when I used the db.colleciton.find() I get the error: "Unknown server error occurred when processing this request." Code further down the chain is able to retrieving the documents. Am I missing something? do I need to set a setting on in azure dB or is this a known issue of the library?
class SalesOrder
{
public string Id { get; set; }
public string PurchaseOrderNumber { get; set; }
public DateTime OrderDate { get; set; }
public string AccountNumber { get; set; }
public decimal SubTotal { get; set; }
public decimal TaxAmt { get; set; }
public decimal Freight { get; set; }
public decimal TotalDue {get; set;}
}
class Program
{
private static readonly string endpointUrl = "endpoint";
private static readonly string authorizationKey = "authorizationKey";
private static readonly string databaseId = "databaseId";
private static readonly string collectionId = "collectionId";
private static DocumentClient client;
static void Main(string[] args)
{
using (client = new DocumentClient(new Uri(endpointUrl), authorizationKey))
{
var collectionLink = UriFactory.CreateDocumentCollectionUri(databaseId, collectionId);
Insert(collectionLink).Wait();
}
}
private static async Task Insert(Uri collectionLink)
{
var orders = new List<object>();
orders.Add(new SalesOrder
{
Id = "POCO1",
PurchaseOrderNumber = "PO18009186470",
OrderDate = new DateTime(2005, 7, 1),
AccountNumber = "10-4020-000510",
SubTotal = 419.4589m,
TaxAmt = 12.5838m,
Freight = 472.3108m,
TotalDue = 985.018m
});
orders.Add(new SalesOrder
{
Id = "POCO2",
PurchaseOrderNumber = "PO15428132599",
OrderDate = new DateTime(2005, 7, 1),
AccountNumber = "10-4020-000646",
SubTotal = 6107.0820m,
TaxAmt = 586.1203m,
Freight = 183.1626m,
TotalDue = 4893.3929m,
});
foreach (var order in orders)
{
Document created = await client.CreateDocumentAsync(collectionLink, order);
Console.WriteLine(created);
}
}
}
count()
andfind()
which I don't think are part of the UI. Can you tell us what the error that you get at the bottom status strip is? – Nick Chapsas