title: How to grant access to two mongodb DB, to write records synchronously, after a celery task is triggered?
body: <p>I have two databases (namely, test and celery). When a celery task is triggered, it will first update the "test" db with results and then update the "celery" db with success/failure message. 
  I have secured these DBs with credentials and followed this method:
  <strong><a href="https://medium.com/@matteocontrini/how-to-setup-auth-in-mongodb-3-0-properly-86b60aeef7e8" rel="nofollow noreferrer">https://medium.com/@matteocontrini/how-to-setup-auth-in-mongodb-3-0-properly-86b60aeef7e8</a></strong></p>
  
  <p>Now, when I run my task, it gives me this error:</p>
  
  <p><strong>pymongo.errors.OperationFailure: not authorized on celery to execute command { createIndexes: "celery_taskmeta", indexes: [ { key: { date_done: 1 }, background: "true", name: "date_done_1" } ] }</strong> </p>
  
  <p>I am using:
  mongodb: 3.4
  mongoengine: 0.16
  django 2.1 and python3</p>
  
  <pre><code>mongoengine.connect(db="test",host=config.host,username="admin_1",
  password="admin1234",authentication_source="admin")
  
  CELERY_BROKER_URL = 'redis://localhost:6379'
  CELERY_RESULT_BACKEND = "mongodb"
  CELERY_ACCEPT_CONTENT = ['application/json']
  CELERY_TASK_SERIALIZER = 'json'
  CELERY_RESULT_SERIALIZER = 'json'
  </code></pre>
  
  <p>Apart from the method mentioned in the link above, I have tried creating an admin user in admin DB like this:</p>
  
  <pre><code>use admin
  db.createUser(
   {
     user: "admin_1",
     pwd: "admin1234",
     roles: [ 
  { 
  role: "dbOwner",
  db: "test" 
  },
  
  { 
  role: "userAdminAnyDatabase",
  db: "admin" 
  },
  
  { 
  role: "dbOwner",
  db: "celery" 
  }
  ]
   }
  )
  </code></pre>
  
  <p>It gives the same error!</p>