objectMongodb.js
function read(id, cb) {
      if (!/^[a-fA-F0-9]{24}$/.test(id)) {return cb ({code: 404, message: 'Not valid ObjectId. Must be 24 hex string or 12 hex binary sequence.'})};
      getCollection(function (err, collection) {
      if (err) { return cb(err); }
      collection.findOne({
        _id: new ObjectID(id)
      }, function (err, result) {
        if (err) { return cb(err); }
        if (!result) {
          return cb({
            code: 404,
            message: 'Not found'
          });
        }
        cb(null, fromMongo(result));
      });
    });
  }
function read(id, cb) {
      if (!/^[a-fA-F0-9]{24}$/.test(id)) {return cb ({code: 404, message: 'Not valid ObjectId. Must be 24 hex string or 12 hex binary sequence.'})};
      getCollection(function (err, collection) {
      if (err) { return cb(err); }
      collection.findOne({
        _id: new ObjectID(id)
      }, function (err, result) {
        if (err) { return cb(err); }
        if (!result) {
          return cb({
            code: 404,
            message: 'Not found'
          });
        }
        cb(null, fromMongo(result));
      });
    });
  }
function read ( id , cb ) { if ( ! / ^[a-fA-F0-9]{24}$ / . test ( id ) ) { return cb ( { code : 404 , message : 'Not valid ObjectId. Must be 24 hex string or 12 hex binary sequence.' } ) } ; getCollection ( function ( err , collection ) { if ( err ) { return cb ( err ) ; } collection . findOne ( { _id : new ObjectID ( id ) } , function ( err , result ) { if ( err ) { return cb ( err ) ; } if ( ! result ) { return cb ( { code : 404 , message : 'Not found' } ) ; } cb ( null , fromMongo ( result ) ) ; } ) ; } ) ; }
[END create]
[ END create ]