Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-855

user not authorized to execute command createIndexes from pymongo but not from mongo

    • Type: Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Priority: Icon: Blocker - P1 Blocker - P1
    • None
    • Affects Version/s: 2.8, 3.0
    • Component/s: None
    • Labels:
    • Environment:
      MacOSX, Ubuntu

      Hello,

      All of this was tested with mongo 2.6.8 and mongo 3.0
      and i've tested under ubuntu 12.04 for a few but since i'm trying on my own laptop (Mac os X mavericks).

      I can not create database in the second db connection with python-mongo.
      The user i've created has this roles

      > db.getUsers()
      [	{ 	"_id" : "users_dev.look",
      		"user" : "look",
      		"db" : "users_dev",
      		"roles" : [
      			{
      				"role" : "root",
      				"db" : "admin"
      			},
      			{
      				"role" : "readWrite",
      				"db" : "users_dev"
      			},
      			{
      				"role" : "dbOwner",
      				"db" : "users_dev"
      			},
      			{
      				"role" : "dbAdmin",
      				"db" : "users_dev"
      			}
      		] }]
      

      then i'm testing my user in mongo:

      mongo users_dev -u look -p
      > db.user_db.insert({ _id: ObjectId('54fdc2e7664348a5b8523656'), roles: { campaign_api: { history: [], role: "ghost", _cls: "UserAPI" } }, login: "backend", password: "G" })
      WriteResult({ "nInserted" : 1 })
      
      bash-3.2$ mongo users_dev -u look -p
      MongoDB shell version: 3.0.0
      Enter password:
      connecting to: users_dev
      > db.user_db.find()
      { "_id" : ObjectId("54fdc2e7664348a5b8523656"), "roles" : { "campaign_api" : { "history" : [ ], "role" : "ghost", "_cls" : "UserAPI" } }, "login" : "backend", "password" : "G" }
      > db.user_db.remove(ObjectId("54fdc2e7664348a5b8523656"))
      WriteResult({ "nRemoved" : 1 })
      > db.user_db.find()
      > db.user_db.insert({1:1})
      WriteResult({ "nInserted" : 1 })
      

      as everything seem to work i'm now trying with python-mongo:

      # Connection 1.
      Going to connect to db: {'urli': 'mongodb://localhost/', 'pwd': 'pwd', 'db': 'promo', 'user': 'write', 'port': 27017}
      Connected to Db MongoClient('localhost', 27017)
      # Connection 2. db users_dev
      Going to connect to db: {u'pwd': u'pwd', u'urli': u'mongodb://localhost/', u'port': 27017, u'user': u'look'} - users_dev
      Connected to Users MongoClient(u'localhost', 27017)
      # The error that happen when i try to save my own document
      # UserDb is defined by myself as a model
      # u = UserDb(login="test", password="test", roles="viewer")
      # u._meta["db_alias"] = alias_connection_2
      # u._collection = None
      # u.save()
      Could not save document (command SON([('createIndexes', u'user_db'), ('indexes', [{'name': u'login_1', 'key': SON([('login', 1)]), 'unique': True, 'background': False, 'sparse': False, 'dropDups': False}])]) on namespace users_dev.$cmd failed: not authorized on users_dev to execute command { createIndexes: "user_db", indexes: [ { name: "login_1", key: { login: 1 }, unique: true, background: false, sparse: false, dropDups: false } ] })
      Could not save document (not authorized on users_dev to execute command { insert: "user_db", ordered: true, writeConcern: { w: 1 }, documents: [ { _id: ObjectId('54fdc66e664348a9cd1e4e43'), roles: { campaign_api: { history: [], role: "ghost", _cls: "UserAPI" } }, login: "backend", password: "G" } ] })
      

      It's probably my fault, but after posting on stackoverflow, with no answer i lose hope.
      Is this a bug from me or from your side ?

      Thanks a lot.

            Assignee:
            bernie@mongodb.com Bernie Hackett
            Reporter:
            lumy lumy
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: