0

I have a Meteor app running on Heroku with a Mongo database addon through Compose (previously MongoHQ).

I would like to insert documents into this database from an entirely different app (Python/Django, not Meteor). So I installed pymongo into my Django app, got the connection URI for mongodb configured correctly, and so forth.

However, when I try to call the following line:

my_dict_collection.update({'id': my_dict['id']}, my_dict, upsert=True)

I get the following error:

OperationFailure: not authorized for upsert on meteor.my_dict_collection

Why is this happening, and how can I get past it?

tadasajon
  • 14,276
  • 29
  • 92
  • 144

2 Answers2

0

If you can do upsert ops in meteor, you should be able to do them in any other app too.

Did you configure it as follows?

DATABASES = {
    'default' : {
        'ENGINE' : 'django_mongodb_engine',
        'NAME' : 'my_database',
        'HOST' : 'database_host',
        'PORT' : 'database_port',
        'USER' : 'database_user',
        'PASSWORD' : 'database_password',
        'OPTIONS' : {
            'slave_okay' : True,
            'tz_aware' : True,
            'network_timeout' : 42,
            ...
        }
    }
}

See documentation here.

Using the credentials you get from:

heroku config:get MONGO_URL

It should give you a mongodb url in the format of:

mongodb://database_user:database_password@database_host:database_port/database_name

The url above may have a comma-separated list of alternative hostnames. I am not sure if django-mongodb supports that, so you may have to use only one them.

d_inevitable
  • 4,381
  • 2
  • 29
  • 48
  • Thanks! I'm also not using django-mongodb. I'm using the correct mongodb URI, which I got from heroku config as you described. I'm not configuring the Mongo database connection in `settings.py`, though -- rather, I'm just passing the full URI to the `pymongo.MongoClient()`. Is it possible to configure two databases in `settings.py`? – tadasajon Nov 07 '14 at 22:48
  • Yes you can. The above example will designate that database as "default". You can add more databases by any name. – d_inevitable Nov 07 '14 at 22:52
  • It looks like django-mongodb-engine requires me to use a fork of Django. I'd rather just stick to standard Django. See: https://stackoverflow.com/questions/26812274/django-1-7-configure-app-that-has-default-postgresql-db-to-also-use-secondary – tadasajon Nov 08 '14 at 00:26
0

Alternatively you could just create a Meteor.method in your app and then call that using a ddp client. See http://www.meteorpedia.com/read/DDP_Clients#Python

zimt28
  • 705
  • 2
  • 7
  • 20