Can we pass a SqlQuerySpec object as a parameter to stored procedure in Document Db? I think this gives us flexibility to send parameterized SQL text and parameters to procedure. If this is not possible, I would like to know if it is possible to access the complete SQL from the SqlQuerySpec.
The server-side API takes the same JSON string as the REST and node.js APIs. The SqlQuerySpec
type for the .NET SDK actually translates to this before sending it up when doing a regular query.
So, here are two ways you can compose the parameterized query from within your stored procedure.
In the package of parameters that you send to your stored procedure, include a JSON string like this:
'''
{
"query": "SELECT * FROM books b WHERE (b.Author.Name = @name)",
"parameters": [
{"name": "@name", "value": "Herman Melville"}
]
}
'''
You may be able to pass the string directly into a call to Collection.queryDocuments()
but you may have to do JSON.parse(<your string>)
before calling Collection.queryDocuments()
filterQuery
object in the JavaScript of your stored procedure.