Using Visual Studio v15.5.7 Community - What Azure Function template was used to generate the code shown in Input - C# example 2? (found at: https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-cosmosdb#input---example-2)
using System.Net;
using System.Net.Http;
using System.Collections.Generic;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
[FunctionName("CosmosDBSample")]
public static HttpResponseMessage Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequestMessage req,
[CosmosDB("test", "test", ConnectionStringSetting = "CosmosDB", SqlQuery = "SELECT top 2 * FROM c order by c._ts desc")] IEnumerable<object> documents)
{
return req.CreateResponse(HttpStatusCode.OK, documents);
}
The above code results in the following errors:
Severity Code Description Project File Line Suppression State
Error CS0246 The type or namespace name 'CosmosDBAttribute' could not be found (are you missing a using directive or an assembly reference?)
Severity Code Description Project File Line Suppression State
Error CS0246 The type or namespace name 'CosmosDB' could not be found (are you missing a using directive or an assembly reference?)
Severity Code Description Project File Line Suppression State
Error CS0246 The type or namespace name 'ConnectionStringSetting' could not be found (are you missing a using directive or an assembly reference?)
I am trying to find examples of serverless functions that insert data into a CosmosDB collection (via POST command) as well as reading data from a CosmosDB collection (via POST or GET parameters). Any examples, links would be most helpful.
ALSO - WHERE do I find the documentation for binding syntax, ie:
[HttpTrigger(AuthorizationLevel.Anonymous, "get")]
[CosmosDB("test", "test", ConnectionStringSetting = "CosmosDB", SqlQuery = "SELECT top 2 * FROM c order by c._ts desc")]
I have been unable to locate ANY resource in docs that explains binding syntax. Looking for something like:
[BindingName( param1, param2, param3, ...)]
Where:
BindingName = HttpTrigger
param1 = Description of param1, required/optional?, valid values, etc.
param2 = Description of param2, required/optional?, valid values, etc.
Having examples is nice -- but I would really like the UNDERSTAND the code and have some detailed explanations as to what each parameter is used for.
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
@bdcoder2 Thanks for reporting the issue! We are investigating and will get back to you.
[CosmosDB("test", "test", ConnectionStringSetting = "CosmosDB", SqlQuery = "SELECT top 2 * FROM c order by c._ts desc")]
Should be:
[DocumentDB("test", "test", ConnectionStringSetting = "CosmosDB", SqlQuery = "SELECT top 2 * FROM c order by c._ts desc")]
@bdcoder2 I am assigning this to the content author to better answer your question.
@ggailey777 please advise.
@tdykstra can you take a look at this issue? I think that there is a versioning issue where older packages still have the DocumentDb attribute. You made the recent change to CosmosDb, which is I think the attribute in the newer version. Thanks!
@bdcoder2 there was an API change between versions of the NuGet packages, which a result of a product name change. CosmosDBAttribute is the name in the newer version and DocumentDBAttribute is the name in the prior version. Thanks for reporting this issue, @tdykstra is working on a fix to clarity this in the documentation.
@bdcoder2 is it OK if we close this issue?
The code example on the original request (content page) still needs to be updated, i.e.:
[HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequestMessage req,
[CosmosDB("test", "test", ConnectionStringSetting = "CosmosDB", SqlQuery = "SELECT top 2 *
should be
[HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequestMessage req,
[DocumentDB("test", "test", ConnectionStringSetting = "CosmosDB", SqlQuery = "SELECT top 2 *
that is: "CosmosDB" should be changed "DocumentDB" in all instances; otherwise, the code will not compile and "CosmoDB" is an unknown name / reference.
I have a PR to fix that and am just waiting on a review before I can sign off on it to get it merged. I hope to get that done today.
I have same issue, is there some fix for this now?
I have same issue, is there some fix for this now?
@merso0027 If you're running 2.x and getting The type or namespace name 'CosmosDB' could not be found (are you missing a using directive or an assembly reference?) then you need to install the Microsoft.Azure.WebJobs.Extensions.CosmosDB package.
Most helpful comment
I have same issue, is there some fix for this now?