There is something wrong with this colection.find().
What I am trying to do with the collection.find() code is, to determine if I have any duplicates before insertion.
I'm trying to log results.length to determine that.
mongodb.Db.connect(process.env.MONGOHQ_URL, function(error, client) {
if (error) {
return log("Unable to connect to database: " + error);
}
client.collection("scores", function(error, collection) {
var duplicate;
if (error) {
return log("Unable to access database: " + error);
}
if (!inputCheck(obj)) {
return log("Input is invalid");
}
collection.find({
game_title: obj.game_title,
username: obj.username,
score: obj.score
}, function(error, cursor) {
if (error) {
return log("Unable to save record: " + error);
}
cursor.toArray(function(error,results) {
return log(results.length());
});
});