mongodb_connect.js 708 Bytes
var mongoose = require('mongoose');
mongoose.connect('mongodb://username:pwd@host/dbname');
var db = mongoose.connection;

//연결실패
db.on('error', function(){
    console.log('Connection Failed!');
});
//연결 성공
db.once('open', function() {
    console.log('Connected!');
});



var testSchema = mongoose.Schema
({
	name: String
});

var TestModel = mongoose.model("TestModel", testSchema);

/*
var test = new TestModel({ name: "test" });

test.save(function(err, test)
{
    if(err){console.log(err);}
    else{console.log("Success!");}
    console.log("ok4");
});
*/

TestModel.find(function(err, test){
    if(err){console.log(err);}
    else{
        console.log(test);
    }
});


db.close()