0

i am trying to work with Azure's DocumentDb to validate the user credentials for login but i am not able to get the proper result.

Some Points: 1. this is a partitioned collection and i am passing the partition key. 2. i am passing an array as parameter.

Here is my Code for calling the procedure:

response = await client.ExecuteStoredProcedureAsync<string>(storedProcedurelink, new RequestOptions { PartitionKey = new PartitionKey(partitionKey) }, new dynamic[]{param});

and here is my code for the procedure:

function sample(param) {
var collection = getContext().getCollection();
var query = 'SELECT * FROM c where c.logindata.email="'+param[0]+'" and c.logindata.password="'+param[1]+'" and c.userid>0';
// Query documents and take 1st item.
var isAccepted = collection.queryDocuments(
    collection.getSelfLink(),
    query,
    function (err, feed, options) {
if (err) throw err;
if (!feed || !feed.length) getContext().getResponse().setBody('no docs found');
else getContext().getResponse().setBody(JSON.stringify(feed));

});
if (!isAccepted) throw new Error('The query was not accepted by the server.');
}

I am able to execute the query in the query explorer and get the proper result but when i call the procedure it always gives no docs found. I don't know what i am doing wrong, can someone point me in right direction.

1 Answer 1

1

I don't know what i am doing wrong.

As param[0] and param[1] can't get the expeted result in store procedure.We can test it from the Azure portal.

enter image description here

can someone point me in right direction.

Please have a try to use 2 paramters in your case.

function sample(email,password) {
var collection = getContext().getCollection();
var query = 'SELECT * FROM c where c.logindata.email="'+email+'" and c.logindata.password="'+password+'" and c.userid>0';
// Query documents and take 1st item.
var isAccepted = collection.queryDocuments(
    collection.getSelfLink(),
    query,
    function (err, feed, options) {
if (err) throw err;
if (!feed || !feed.length) getContext().getResponse().setBody('no docs found');
else getContext().getResponse().setBody(JSON.stringify(feed));

});
if (!isAccepted) throw new Error('The query was not accepted by the server.');
}

And make sure that we can get the expected result from Azure Portal script exploer.

In the C# code

      var user = "xxxxx";
      var password = "xxxx";
      var response = await client.ExecuteStoredProcedureAsync<string>(storedProcedurelink, new RequestOptions { PartitionKey = new PartitionKey(partitionKey) },user,password);

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.