Comments (7)
See: http://api.mongodb.org/python/current/api/pymongo/mongo_client.html
"The host parameter can be a full mongodb URI, in addition to a simple hostname."
And: http://docs.mongodb.org/manual/reference/connection-string/
from bottle-cork.
Could I therefore use:
class MongoDBBackend(Backend):
def __init__(self, db_name='cork', hostname='os.environ[\'OPENSHIFT_MONGODB_DB_URL\']', initialize=False):
"""Initialize MongoDB Backend"""
connection = MongoClient(hostname)
db = connection[db_name]
Two things I am confused about:
- Is the syntax correct for
hostname
value? - Would each user therefore be accessing a connection where they were logged in with the MongoDB admin username and password (as that is all in the
OPENSHIFT_MONGODB_DB_URL
environment variable - see first post)? And if so is that a problem?
Sorry for asking so many questions, but I seem to be coming up against a few issues when implementing. Nevertheless, I hope they may be helpful for others implementing on OpenShift.
from bottle-cork.
No need to modify mongodb_backend.py - in your own code you can do:
dbname = 'mydbname'
hostname = os.environ['OPENSHIFT_MONGODB_DB_URL']
port = os.environ['OPENSHIFT_MONGODB_DB_PORT']
port = int(port)
connection = pymongo.MongoClient(hostname=hostname, port=port)
db = connection[dbname]
"connection" would be used by any user within the same application. It should have limited access rights, e.g. update the collection that belong to your webapp and nothing more.
from bottle-cork.
Thank you for the clarification, that makes sense to me.
from bottle-cork.
I ran my application from shell and got error:
File "mybottleapp.py", line 47, in populate_mongodb_backend
connection = pymongo.MongoClient(hostname=hostname)
NameError: global name 'hostname' is not defined
Looking at the class definition of MongoDBBackend
in mongodb_backend.py, 'hostname' is defined as a parameter.
This is the code in my application:
def populate_mongodb_backend():
mb = MongoDBBackend(db_name='cork-example', initialize=True,
hostname = os.environ['OPENSHIFT_MONGODB_DB_URL'],
connection = pymongo.MongoClient(hostname=hostname)
)
Note the value of OPENSHIFT_MONGODB_DB_URL
is:
mongodb://admin:[email protected]:27017/
Update:
I realised host
is the MongoClient
parameter name, not hostname
, so I tried:
def populate_mongodb_backend():
mb = MongoDBBackend(db_name='cork-example', initialize=True,
hostname = os.environ['OPENSHIFT_MONGODB_DB_URL'],
connection = pymongo.MongoClient(host=hostname)
)
And get the same error:
connection = pymongo.MongoClient(host=hostname)
NameError: global name 'hostname' is not defined
from bottle-cork.
That's because the "hostname" variable is not defined. Use:
hostname = os.environ['OPENSHIFT_MONGODB_DB_URL']
from bottle-cork.
working code:
def populate_mongodb_backend():
hostname = os.environ['OPENSHIFT_MONGODB_DB_URL']
connection = pymongo.MongoClient(host=hostname)
mb = MongoDBBackend(db_name='cork-example', initialize=True,hostname = hostname)
.... # the rest is the same
from bottle-cork.
Related Issues (20)
- SQLiteBackend.Table.iteritems() yields wrong data HOT 2
- Doco links to dead-ish downloads page on Github
- Best way to add more user fields to user profile? HOT 1
- Registration email fails if TEMPLATE_PATH is not /views/ HOT 2
- Login timeout too short HOT 1
- make doc error HOT 1
- Subclassing User HOT 2
- Security issue? problematic defaults for hashlib.pbkdf2_hmac HOT 1
- Registration does not check pending_registrations collection for existence of the user name HOT 4
- http://cork.firelet.net/ is down HOT 1
- Missing logging for auditing HOT 5
- pip update? HOT 1
- Documentation website is down HOT 1
- mongo backend doesn't work with mongdb 3.4
- Email Not Sent - Auth Error HOT 6
- TypeError @ _setup_cookie when signing/logging in HOT 1
- Docs not accessible
- Question ? Cork without beaker
- There's an error when installing
- Sqlite code leads to SQL injection vulnerability
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bottle-cork.