0

I am creating a service for Azure Functions written in JavaScript/Node.js and I am getting the below error when attempting to access the function DocumentClient.queryDatabases. I have the correct references installed in Visual Studio Code and through Intellisense can see the queryDatabases method through the following:

var client = require('documentdb').DocumentClient;
client.queryDatabases(...);

Any ideas why the debugger is blowing up with the error?

Exception has occurred: TypeError
TypeError: client.queryDatabases is not a function
    at Object.getOrCreateDatabase (/Users/.../Documents/.../UserModel.js:23:16)
    at Object.<anonymous> (/Users/.../Documents/.../Test.js:5:11)
    at Module._compile (module.js:638:14)
    at Object.Module._extensions..js (module.js:652:10)
    at Module.load (module.js:560:32)
    at tryModuleLoad (module.js:503:12)
    at Function.Module._load (module.js:495:3)
    at Function.Module.runMain (module.js:682:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:613:3

References

1 Answer 1

1

First, you need to initialize the client with your DocumentDB host and auth key. And then call the function via this client.

Example:

var DocumentDBClient = require("documentdb").DocumentClient;

var endpoint = '<host>';
var primaryKey = '<authKey>';
var client = new DocumentDBClient(endpoint, { masterKey: primaryKey });

var querySpec = {
    query: 'SELECT * FROM root r WHERE  r.id = @id',
    parameters: [
        {
            name: '@id',
            value: databaseId
        }
    ]
};

client.queryDatabases(querySpec).toArray(function (err, results) {
    if(err) return console.log(err);
    console.log(results);
});
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.