gdy przekazuje limit:limit wyskakuje mi błąd w konsoli status 500, a gdy wpisze recznie limit:5 pokazuje mi 5 rekordow, konsolowanie zmiennej limit pokazuje 5. W czym jest problem?
server.js
var express = require("express"),
mongo = require("mongodb"),
MongoClient = mongo.MongoClient,
app = express();
dbUrl = "mongodb://localhost:27017/List";
app.use(express.static(__dirname + "/public"))
app.get("/", function (req, res) {
res.sendfile("index.html")
})
app.get("/list", function (req, res) {
var limit = req.query.limit;
MongoClient.connect(dbUrl, function (err, db) {
if (err) {
res.status(500);
res.json({
error: true
});
return;
}
db.collection("games").find({}, {
limit: limit
}).toArray(function (err, docs) {
if (err) {
res.status(500);
res.json({
error: true
});
return;
}
res.json(docs)
});
});
});
app.listen("8000", function () {
console.log("Server active");
})
Router.js
(function () {
APP.Routers.Router = Backbone.Router.extend({
routes: {
"": "showList"
},
showList: function () {
var games = new APP.Collections.GamesList(),
view = new APP.Views.GamesList({
collection: games
});
games.fetch({
reset: true,
data: {
limit: 5
}
});
}
})
})();