我正在尝试学习 MongoJS,但它不起作用。
到目前为止我写了这段代码 -
/* Basics */
var express = require('express'),
app = express(),
server = require('http').createServer(app),
io = require('socket.io').listen(server),
db = require("mongojs").connect("mydb", ["users"]);
server.listen(27017, null);
io.set('transports', ['xhr-polling']);
// routing
app.get('/', function (req, res) {
res.sendfile("index.html");
app.use(express.static(__dirname));
});
db.users.save({username : "admin"}, function(err, saved) {
if( err || !saved ) { console.log("User not saved"); }
else { console.log("User saved"); }
});
它登录到控制台“用户未保存”,但为什么呢?我做错了什么?
提前致谢