MongoDB-错误:无效的架构,预期的mongodb [英] MongoDB - Error: invalid schema, expected mongodb

查看:85
本文介绍了MongoDB-错误:无效的架构,预期的mongodb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用MEAN Stack构建应用程序的新手,我正在尝试构建一个实时聊天应用程序,这是我的服务器端:

I'm new in building application with MEAN Stack, I'm trying to build a real time chat app, here is my server side :

console.log("Server running...!");

var mongo=require('mongodb').MongoClient;
var client=require('socket.io').listen(8080).sockets;

mongo.connect('localhost:27017/db/chat',function(err,db){
if(err)  throw err;

client.on('connection',function(socket){
console.log('someone has connected !');

//waiting for input
socket.on('input',function(data){
console.log(data);
});

});

});

我确定我创建了一个与mongodb聊天的数据库,mongo也正在等待连接.但是,当我使用节点server.js运行服务器时,会发生错误:

I am sure that i created a data base called chat with mongodb, also mongo is waiting for connection. But when i run the server with node server.js an error occurs :

Server running...!
C:\Users\azus\Desktop\Psirt\codemaster\node_modules\ mongodb\lib\url_parser.js:20
  throw new Error('invalid schema, expected mongodb');
  ^

Error: invalid schema, expected mongodb
at module.exports (C:\Users\azus\Desktop\Psirt\code-master\node_modules\mong
 odb\lib\url_parser.js:20:11)
at connect (C:\Users\azus\Desktop\Psirt\code-master\node_modules\mongodb\lib
 \mongo_client.js:125:16)
at Function.MongoClient.connect (C:\Users\azus\Desktop\Psirt\code-master\nod
e_modules\mongodb\lib\mongo_client.js:109:3)
at Object.<anonymous> (C:\Users\azus\Desktop\Psirt\code-master\server.js:6:8
)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:139:18)

C:\Users\azus\Desktop\Psirt\code-master>

在这个阶段,我被封锁了几个星期,有人可以帮忙吗?

I had been blocked at this phase for weeks, could anyone help on this?

谢谢.

推荐答案

这是因为您使用的连接字符串格式不正确.

This is because you are using the connection string in an improper format.

您正在使用localhost:27017/db/chat,而它应该是mongodb://localhost:27017/db/chat

You are using localhost:27017/db/chat while it should be mongodb://localhost:27017/db/chat

连接字符串的模式为mongodb://<HOSTNAME>:<PORT>/<DBNAME>

供参考的文章: https://mongodb.github.io/node-mongodb-native/api-generated/mongoclient.html#mongoclient-connect

这篇关于MongoDB-错误:无效的架构,预期的mongodb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆