problem about node-mongodb-native-Collection of common programming errors

  • Msencenb
    node.js exception-handling error-handling node-mongodb-native
    Simplified code… but the basic scenario is I’m doing a findOne query with Mongo to lookup a user, but if the user doesn’t exist it throws an error that crashes the entire webserver. Can someone point me in the right direction for correctly wrapping these errors so they don’t bring everything down?The Route:server.get(‘/v1/user/:token’, function(req,res){console.log(“user endpoint hit”);var user = users.findOne({token:req.params.token}, function(err,user){if (user) {res.json({token:user.token,c

  • heinob
    node.js mongodb node-mongodb-native
    I am experiencing a very strange problem. I am importing some big xml-files and store them into mongoDB. The algorythm is a typical async loop:doLoop = function( it, callback_loop ) {if( it < no_of_items ) {storeToMongo( …, function( err, result ) {…doLoop( it+1, callback_loop );});} else {callback_loop();} }; doLoop( 0, function() {… });Now (suddenly without any remarkable change in the code) I get the following error while performing the loop:events.js:72throw er; // Unhandled ‘error’

  • fthinker
    node.js express node-mongodb-native
    Examining the code below, how is it possible that the try/catch block is catching the “Route Error”? My understanding is that the callback registered to the ‘/’ route is executed on the main event loop and as such the exception cannot be caught by the specified try/catch block because it is not part of the call stack where the callback is executed.var express = require(‘express’) ; var app = express(); var http = require(‘http’);var mongod = require(‘mongodb’);var server_conf = new mongod.Serv

  • Scott Switzer
    node.js express node-mongodb-native
    I am using node + express to create a simple REST API, and am trying to separate out routing logic from db logic. I am having a problem getting access to the DB from the routes.Here is my server.js code:var express = require(‘express’), path = require(‘path’), http = require(‘http’), mongo = require(‘mongodb’);// Configure Express app var app = express(); app.configure(function () {app.set(‘port’, process.env.PORT || 3000);app.use(express.logger(‘dev’)); /* ‘default’, ‘short’, ‘tiny’, ‘dev’ */

  • Ovidiu CICAL
    node.js mongodb node-mongodb-native
    Can someone enlighten me with a solution for the following situation?I have a logging application written in nodeJS express framework and using MongoDB collections. I managed to get the results from a collection, but I want to iterate on the results, query another collection based on the reference ID from the first query and append more values to the initial results, then send the response to the client.I will paste bellow what I have now coded, but I cannot get it to work. I’m either doing it w

  • user2194521
    javascript node.js mongodb node-mongodb-native
    Something like thisvar joined = function(arr) {var res = [];for (var i in arr) {var u = DB.getUser(arr[i].user_id, function(user) {return user;});arr[i].user = u;res = arr[i];}return res; }I need to get user variable from DB.getUser scope.

  • nihulus
    javascript node.js mongodb express node-mongodb-native
    Basicly I want to check if a specific data exists in the database before inserting data(im using native mongodb driver), so what I tried is using collection.findOne() to check if data exists, if the property of the attribute is null the collection.insert() performs. Apparently my code is not working according the logic, please someone enlighten me! some of my code:exports.addUser = function(req, res) {var twitterId = req.body.provider;var userEmail =;db.collection(‘users’, functio