[英]NodeJs Mongoose + Mongo, connecting to localhost
I just updated to node 0.5.10 from 0.4.11 and my version of mongoose from 2.0.2 to 2.3.13 however I can no longer connect to localhost. 我刚刚从0.4.11更新到节点0.5.10,我的mongoose版本从2.0.2更新到2.3.13但是我无法再连接到localhost。 My code has not changed at all, and I can still connect to my production server on mongolab. 我的代码根本没有改变,我仍然可以在mongolab上连接到我的生产服务器。 I can connect to my local db using a gui (MongoHub) just going through localhost. 我可以使用gui(MongoHub)通过localhost连接到我的本地数据库。 I am now running out of ideas. 我现在已经没想完了。 I've tried variations on the following connection strings which both should work in my option. 我已经尝试了以下连接字符串的变体,这两个字符串都可以在我的选项中使用。
mongodb://localhost:27017/mydb
mongodb://localhost/mydb
I have even created a very basic single app to just save something to my localhost but to no avail. 我甚至创建了一个非常基本的单个应用程序,只是保存到我的本地主机,但无济于事。 Ideas are very welcome! 非常欢迎您的想法!
var mongoose = require('mongoose');
var db = mongoose.connect('mongodb://localhost/SomeDb');
var Schema = mongoose.Schema;
var Posts = new Schema({
name : String,
});
mongoose.model('Post', Posts);
function createNewPost(){
var Post = mongoose.model('Post');
var post = new Post({name:'new name'});
post.save(function(err){
console.log("saving");
if(!err){
console.log('Post saved.');
}
});
}
After debugging using the mongodb native I found that 127.0.0.1 works. 使用mongodb native调试后我发现127.0.0.1正常工作。 I have not idea but I am back up and running. 我不知道,但我已经恢复正常运行。
mongodb://127.0.0.1/mydb
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.