我正在编写一个基本的Google Cloud功能,它将从MongoDB Atlas查询MongoDB群集.我正在写入Google控制台,我确定将"mongodb":"^ 3.0.2"添加到package.json文件中的依赖项中.
这是函数(为了安全起见,我在uri中替换了有效密码等):
/**
* Responds to any HTTP request that can provide a "message" field in the
body.
*
* @param {!Object} req Cloud Function request context.
* @param {!Object} res Cloud Function response context.
*/
exports.myPackage = (req, res) => {
var MongoClient = require('mongodb').MongoClient;
var uri = "mongodb+srv://<USERNAME>:<PASSWORD>@<CLUSTER-NAME>-vtbhs.mongodb.net/test";
MongoClient.connect(uri, function(err, client) {
if (err) {
console.log('err');
console.log(err);
} else {
const collection = client.db("test").collection("devices");
}
});
res.status(200).send('Success');
}
Run Code Online (Sandbox Code Playgroud)
我确定驱动程序是最新的,我直接从Atlas文档中复制了大部分代码.我已将Atlas的所有IP列入白名单进行测试.
每次运行该函数时,我都会在connect回调中收到以下错误:
"{ Error: querySrv ESERVFAIL _mongodb._tcp.<CLUSTER-NAME>-vtbhs.mongodb.net …Run Code Online (Sandbox Code Playgroud) mongodb node.js google-cloud-platform google-cloud-functions mongodb-atlas
我可以使用cURL来获得令牌,但是Postman还是没有运气。这是curl命令:
curl -X POST -H "Cache-Control: no-cache" -H "Content-Type: application/x-www-form-urlencoded" -d 'client_id=<your_id>&client_secret=<your_secret>&grant_type=client_credentials&scope=https%3A%2F%2Fapi.botframework.com%2F.default' 'https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token'
Run Code Online (Sandbox Code Playgroud)
按照Microsoft官方文档中有关使用REST开发机器人的说明,我在Postman中发送了一个请求,要求获取oauth令牌以与机器人REST API配合使用。
这是我在Postman中的设置(正在使用Interceptor,因此我可以指定Host):
标头

身体

而且,这是响应:
{
"error": "invalid_scope",
"error_description": "AADSTS70011: The provided value for the input parameter 'scope'
is not valid. The scope https%3A%2F%2Fapi.botframework.com%2F.default is not valid.
\r\nTrace ID: 8b09d0ba-3ec0-4f15-9280-7527d46c1600\r\nCorrelation ID: 43b0fa8f-5b73-444c-
a1e4-9f3dd82c0d86\r\nTimestamp: 2017-05-30 22:17:05Z",
"error_codes": [70011],
"timestamp": "2017-05-30 22:17:05Z",
"trace_id": "8b09d0ba-3ec0-4f15-9280-7527d46c1600",
"correlation_id": "43b0fa8f-5b73-444c-a1e4-9f3dd82c0d86"
}
Run Code Online (Sandbox Code Playgroud)
有谁知道这是什么问题吗?我按照说明进行操作,并且确定客户端ID和机密ID是正确的。在此先感谢您的帮助!