title: Node.js / REST: How to get _id from url
body: <p>I have followed next tutorial: <a href="http://cwbuecheler.com/web/tutorials/2014/restful-web-app-node-express-mongodb/" rel="nofollow">http://cwbuecheler.com/web/tutorials/2014/restful-web-app-node-express-mongodb/</a>
  After a few days I got it all working, but updating the userdatabase is for the reader themselves.</p>
  
  <p>I have edited the jade template and added some javascript for a click event on an update link.
  I could even retrieve the userID from a listed testuser. Tested this with an alert and is ok.</p>
  
  <p>javascript for click event: global.js </p>
  
  <pre><code>function showUser2Edit(event){
      event.preventDefault();
  
      var userID = $(this).attr('rel');
      // alert (userID);// _id from MongoDB, ok!
  
      // jQuery AJAX call for JSON
      $.getJSON( '/users/userdata/' + userID, function( data ) {
          // populate edit form
          alert (JSON.stringify(data));
      }
  }  
  </code></pre>
  
  <p>in users.js (server-side node.js)</p>
  
  <pre><code>/*
   * GET userData
   */
  router.get('/userdata', function(req, res) {
      var db = req.db;
      var collection = db.get('users');
          collection.find({_id: ?????? },{},function(e,docs){
          res.json(docs);
      });
  });
  </code></pre>
  
  <p>2 problems i really have no idea how to solve them:</p>
  
  <p>Ajax call will be to: users/userdata/_id (_id is a long string, automatically added as key by MongoDB). But how do I add this to this router function?</p>
  
  <p>This _id must be placed in the where part of collection.find(....), but how do i extract this from the url?</p>
  
  <p>Thanks in advance for any help!</p>
  
  <p>The mark for duplication is not correct,that one is about a query parameter: ?color=red, how can I access the variabe color?,mines is a REST system where the id is part of the url itself.</p>