I've written an Azure function which halfway through the function, builds up a CosmosDb document query and excecutes it to find a document in the collection.
As I have the binding for the CosmosDB specified with no Id or Sql query supplied, does this retrieve the entire collection by default? If so is there a way to prevent this,as I only want to query the collection once I have built the document query and return a result.
Do I need to specify a direction of inout to achieve this?
public static class SynchroniseMemberData
{
[FunctionName("SynchroniseMemberData")]
public static void Run([EventGridTrigger] EventGridEvent eventGridEvent, ILogger log,
[CosmosDB(
databaseName: "MembersData",
collectionName: "Members",
ConnectionStringSetting = "offers_DOCUMENTDB"),
]
DocumentClient client,
[CosmosDB(
databaseName: "MembersData",
collectionName: "Members",
ConnectionStringSetting = "offers_DOCUMENTDB")
]
out object document
)
{
log.LogInformation(eventGridEvent.Data.ToString());
MemberDetails memberDetails = JsonConvert.DeserializeObject<MemberDetails>(eventGridEvent.Data.ToString());
Uri collectionUri = UriFactory.CreateDocumentCollectionUri("MembersData", "Members");
var query = client.CreateDocumentQuery<Document>(collectionUri).Where(p => p.Id == memberDetails.id);
var member = query.AsEnumerable().FirstOrDefault();
if (member == null)
{
document = new
{
//Create New Member
};
}
else
{
//update member details and save back
document = member;
}
}
CosmosDBTrigger
function? Post your function code if possible. – Chris BDocumentClient
binding for the input so not actually getting any results for anything until you do your query? – Chris B