Mongoose, Cygwin and MongoDB - not saved

I am completely new to mongo and node.js, so I'm still at the game stage.

I am running Windows 7, so I need to use Cygwin to use node.js. For mongo, I copied the binaries to the cygwin / bin / folder and started mongod - this still works. I can create databases, tables, etc.

Now I want to use Mongoose with node.js. I installed it through npm and it seems to work, but I cannot save my entries.

Here is the code I'm using:

var mongoose = require('mongoose'),
sys  = require('sys'),
Schema = mongoose.Schema;

mongoose.connect('mongodb://localhost/test');

// schema definition
var User = new Schema({
    name     : String
});

mongoose.model('User', User);

// creating an user
var UserModel = mongoose.model('User'); 
var u = new UserModel();
u.name = 'John';

// inserting
u.save(function(){
    sys.puts('Saved!');
});

I never see my "saved"! and he does not save it. Any suggestions?

+3
source share
1 answer

Just ran into this problem. Try adding the following line to the hosts file:

127.0.0.1  localhost

Your hosts file should be somewhere around C:\Windows\System32\drivers\etc

+3
source

Source: https://habr.com/ru/post/1793690/


All Articles