Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-932

mongodb url format error

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Trivial - P5 Trivial - P5
    • None
    • Affects Version/s: 2.2.2
    • Component/s: MongoDB 3.4
    • Labels:
    • Environment:
      Mac os 10.12.3, nodejs 7.4.0

      In documents, you suggest user use connect mongodb like this:

      var MongoClient = require('mongodb').MongoClient,
        f = require('util').format,
        assert = require('assert');
      
      var user = encodeURIComponent('dave');
      var password = encodeURIComponent('abc123');
      var authMechanism = 'DEFAULT';
      var authSource = 'myproject';
      
      // Connection URL
      var url = f('mongodb://%s:%s@localhost:27017?authMechanism=%s&authSource=',
        user, password, authMechanism, authSource);
      

      error 1:

      When I run this code, it gives me mongodb name has a bad character [space]
      And I print the URL:mongodb://dave:abc123@localhost:27017?authMechanism=DEFAULT&authSource= myproject

      I add '%s' to the end of url, solved.

      error 2:

      Run code by fixed url, it give me: missing delimiting slash between hosts and options

      I solved this problem by modify the URL like this: mongodb://%s:%s@localhost:27017/myproject?authMechanism=%s

      This time it work perfect.

      Is this a bug or I code something wrong?

            Assignee:
            Unassigned Unassigned
            Reporter:
            maicss maic
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: