我在一个网站上工作,需要连接到我的mongodb数据库(而不是本地数据库),现在我尝试在我的wamp localhost上运行此代码(附加),但nodejs部分未运行 我该如何解决?而且这个问题也会出现在真实的服务器中吗?
<html>
<body>
<div id="aa">
</div>
<script>
document.getElementById("aa").innerHTML = "aaa";
var MongoClient = require('mongodb').MongoClient;
document.getElementById("aa").innerHTML = "aaaas";
var uri = "mongodb://<myrealkay>:<myrealpassword>@routeplan-shard-00-00-d416l.gcp.mongodb.net:27017,routeplan-shard-00-01-d416l.gcp.mongodb.net:27017,routeplan-shard-00-02-d416l.gcp.mongodb.net:27017/test?ssl=true&replicaSet=routeplan-shard-0&authSource=admin&retryWrites=true";
alert(uri);
MongoClient.connect(uri, function(err, db) {
var collection = client.db("calc").collection("items");
// perform actions on the collection object
if (err) throw err;
var dbo = db.db("calc");
var a = dbo.collection("items").find({}).toArray();
document.getElementById("aa").innerHTML = "assaa";
});
</script>
</body>
</html>