I'm calling my DocumentDB database to query for a person. If the person is not in the database, I'm then trying to insert the person into my collection.
When I check the collection, I see that the new person is being created but my code just seems to hang where I make the second call to insert the person into the collection. Any idea why my code is hanging? I'm not including all the code to save space e.g. GetDatabaseAsync(), GetCollectionAsync(), etc. are all working.
using (client = new DocumentClient(new Uri(endPointUrl), authorizationKey))
{
//Get the database
var database = await GetDatabaseAsync();
//Get the Document Collection
var collection = await GetCollectionAsync(database.SelfLink, "People");
string sqlQuery = "SELECT * FROM People f WHERE f.id = \"" + user.PersonId + "\"";
dynamic doc = client.CreateDocumentQuery(collection.SelfLink, sqlQuery).AsEnumerable().FirstOrDefault();
if (doc == null)
{
// User is not in the database. Add user to the database
try
{
**// This is where the code is hanging. It creates the user in my collection though!**
await client.CreateDocumentAsync(collection.DocumentsLink, user);
}
catch
{
// Handle error
}
}
else
{
// User is already in the system.
user = doc;
}
}
Is it possible that the code hangs because I'm trying to both query and insert a document inside the same USING statement.
Is it a better idea for me to create a new instance of the client and create a separate block to handle the document INSERT?