鏈接數據庫mongodb
var mongoose = require('mongoose'); var schema = mongoose.Schema; // 鏈接MongoDB mongoose.connect("mongodb://localhost:27017"); // 定義模式 var userSchema = new schema({ name : String, sex : String, age : Number }); // 編譯模型 var User = mongoose.model('User', userSchema); //查詢數據 User .find({},function(err,doc){ console.log(doc) }