Hello,
I am working on the final project " Information Security and Quality Assurance Projects - Anonymous Message Board" and getting this error.
TypeError: callback is not a function
at db.collection.find.project.toArray (/app/controllers/handlers.js:100:9)
at result (/rbd/pnpm-volume/c576d8e3-af34-4559-bcf6-a493b4c94c6a/node_modules/.registry.npmjs.org/mongodb/3.2.7/node_modules/mongodb/lib/utils.js:410:17)
at executeCallback (/rbd/pnpm-volume/c576d8e3-af34-4559-bcf6-a493b4c94c6a/node_modules/.registry.npmjs.org/mongodb/3.2.7/node_modules/mongodb/lib/utils.js:402:9)
at handleCallback (/rbd/pnpm-volume/c576d8e3-af34-4559-bcf6-a493b4c94c6a/node_modules/.registry.npmjs.org/mongodb/3.2.7/node_modules/mongodb/lib/utils.js:128:55)
at cursor.close (/rbd/pnpm-volume/c576d8e3-af34-4559-bcf6-a493b4c94c6a/node_modules/.registry.npmjs.org/mongodb/3.2.7/node_modules/mongodb/lib/operations/cursor_ops.js:224:62)
at handleCallback (/rbd/pnpm-volume/c576d8e3-af34-4559-bcf6-a493b4c94c6a/node_modules/.registry.npmjs.org/mongodb/3.2.7/node_modules/mongodb/lib/utils.js:128:55)
at completeClose (/rbd/pnpm-volume/c576d8e3-af34-4559-bcf6-a493b4c94c6a/node_modules/.registry.npmjs.org/mongodb/3.2.7/node_modules/mongodb/lib/cursor.js:898:14)
at _endSession (/rbd/pnpm-volume/c576d8e3-af34-4559-bcf6-a493b4c94c6a/node_modules/.registry.npmjs.org/mongodb/3.2.7/node_modules/mongodb/lib/cursor.js:909:37)
at Cursor._endSession (/rbd/pnpm-volume/c576d8e3-af34-4559-bcf6-a493b4c94c6a/node_modules/.registry.npmjs.org/mongodb-core/3.2.7/node_modules/mongodb-core/lib/cursor.js:195:5)
at Cursor._endSession (/rbd/pnpm-volume/c576d8e3-af34-4559-bcf6-a493b4c94c6a/node_modules/.registry.npmjs.org/mongodb/3.2.7/node_modules/mongodb/lib/cursor.js:231:59)
It seems like something is wrong in somewhere below code but I can not figure out how to solve it.
Handlaer.js
//get most recent 10 bumped threads
exports.getTenThread = function(req, res, callback){
var board = req.params.board
var thread_id = req.body.thread_id
var threadText = req.body.text
MongoClient.connect(CONNECTION_STRING, {useNewUrlParser: true}, function(err, client){
if(err){console.log("Database error: : " + err)}
console.log("MongoClient connected successfully")
var record = []
var db = client.db("MessageBoard");
db.collection(board).find().sort({bumped_on: -1}).project( { reported: 0, delete_password: 0} ).toArray((err, docs)=>{
if (err){
res.json(err);
console.log("Database error: : " + err);
};
for(var i=0; i<10; i++){
record.push(docs[i])
}
callback( null, record);
});
})
}
api.jp
.get(function (req, res){
ThreadController.getTenThread(req, function(err, res){
console.log("its working")
console.log("res",res)
res.json(res);
})
})
Can anyone help me with this?
here is my glitch link: