我已经建立了一个 mongodb Atlas 免费层集群。当我尝试使用节点 js 连接到它时,它会引发错误。我手动和选择当前都将我的 IP 列入白名单。我还尝试将 +srv 添加到我的连接 url 中,但这只会导致更多错误。
这是我试图连接的节点 js 代码
const { MongoClient } = require("mongodb");
const url = "mongodb://user1:password1!@cluster0-shard-00-00-bc7dh.mongodb.net/test?retryWrites=true&w=majority&useNewUrlParser=true&useUnifiedTopology=true";
const client = new MongoClient(url);
async function run() {
try {
await client.connect();
console.log("Connected correctly to server");
} catch (err) {
console.log(err.stack);
}
finally {
await client.close();
}
}
run().catch(console.dir);Run Code Online (Sandbox Code Playgroud)
这是我得到的错误
MongoServerSelectionError: 到 52.64.0.234:27017 的连接在 Timeout._onTimeout (C:\Users\YOUNG\node_modules\mongodb\lib\core\sdam\topology.js:430:30) at listOnTimeout (internal/timers.js:549) 关闭:17) 在 processTimers (internal/timers.js:492:7)
有类似问题的人能够通过将他们的 IP 地址列入白名单来解决它,但它对我不起作用。可能是什么问题?
我尝试允许访问所有 ip,但错误仍然存在,当我将 uri 与 +srv 一起使用时,出现以下错误
MongoServerSelectionError: Authentication …Run Code Online (Sandbox Code Playgroud) 在github中有一个名为mustache.js-master的mustache文件夹的文件.它有许多不同的文件,包括mustache.min.js,mustache.js,bin文件夹,hooks文件夹,spec文件夹,测试等.如何安装小胡子,我只需下载文件并在我的内容中包含mustache.js代码,还是有办法安装文件?
我只是在我的项目文件夹中包含了mustache.js文件,并在我的代码中编写了标记.下面是我编写的一些代码,看它是否有效,来自console.log和document.write的输出都是空的.我的代码有什么问题,或者我应该以不同的方式安装胡子?
<script type ="text/javascript" src ="jquery.js"></script>
<script type="text/javascript" src = "mustache.js"></script>
<script>
var template;
var data;
template = '<div><h2>{{Title}}</h2><p>{{Course}}</p><p>{{Category}}</p></div>';
data = '[{"Title":"Algorithms","Course":"CSI241","Category":"science"},{"Title":"Fluid dynamics","Course":"PHY345","Category":"science"}]';
var html = Mustache.to_html(template,data);
console.log(html);
document.write(html);
</script>
Run Code Online (Sandbox Code Playgroud) 当我尝试将我的html页面链接到我的快递应用程序中的javascript文件时,我在开发人员工具中收到了上述错误.我在一个快速应用程序中运行它,在我的本地计算机上使用hbs渲染引擎.代码段看起来像这样
HTML
<script type="text/javascript" src="file:///public/javascripts/jquery/jquery-2.2.4.min.js"></script>
<script type="/javascript" src="file:///public/javascripts/receiver.js"></script>
<script type="text/javascript" src="file:///public\javascripts\jquery-2.2.4.min.map"></script>Run Code Online (Sandbox Code Playgroud)
这是app.js中设置视图引擎的部分
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hbs');Run Code Online (Sandbox Code Playgroud)
当我检查开发人员工具时,我收到此控制台错误
不允许加载本地资源:file:///public/javascripts/jquery/jquery-2.2.4.js(index):1不允许加载本地资源:file:///public/javascripts/receiver.js( index):1不允许加载本地资源:file:///public/javascripts/jquery-2.2.4.min.map
为什么程序不能访问我的javascripts?
我想在HTML页面的标签中显示一个javascript变量,但是当我单击按钮时它不会出现.谁能告诉我我做错了什么?
HTML
<button name = "presser">go </button>
<p id = "display"></p>
<script type ="text/javascript" src ="jquery.js"></script>
<script type ="text/javascript" src = "processor_file.js"></script>
Run Code Online (Sandbox Code Playgroud)
使用Javascript
$(":button").click(function(){
$.get("middleman.php", {theword: "happen"},function(data,status){
$.getElementById("display").innerHTML = data;
});
});
Run Code Online (Sandbox Code Playgroud)
来自middleman.php的PHP代码
<?php
if(isset($_GET["theword"])){
$token = $_GET["theword"];
echo substr($token, 1, 3);
}
?>
Run Code Online (Sandbox Code Playgroud)
这个词从php页面成功传递到javascript页面,但是当我尝试通过<p>标签显示它时,没有任何反应.