#!/usr/bin/python
import sys
import time
sys.path.append('/Users/pcode/Desktop/mongodb_test/web2py')
from gluon.dal import DAL, Field
db = DAL('mongodb://127.0.0.1:5984/db')
#mongodb test set........
#start with simple data types........
#then inser into mongodb
db.define_table('m_test',
Field('name','text'),
Field('number','integer'))
#########################################################
##### The above code produces the following error
#########################################################
Traceback (most recent call last):
File "./test_mdb_1.py", line 7, in <module>
db = DAL('mongodb://127.0.0.1:5984/db')
File "/Users/pcode/Desktop/mongodb_test/web2py/gluon/dal.py", line
3724, in __init__
raise RuntimeError, "Failure to connect, tried %d times:\n%s" %
(attempts, error)
RuntimeError: Failure to connect, tried 5 times:
'MongoDBAdapter' object has no attribute '_uri'
#########################################################
####### Make the following changes
#########################################################
Line number 3342
FROM:
m = re.compile('^(?P<host>[^\:/]+)(\:(?P<port>[0-9]+))?/(?P<db>.+)
$').match(self._uri[10:])
TO:
m = re.compile('^(?P<host>[^\:/]+)(\:(?P<port>[0-9]+))?/(?P<db>.+)
$').match(self.uri[10:])
Line number 3344
FROM:
raise SyntaxError, "Invalid URI string in DAL: %s" % self._uri
TO:
raise SyntaxError, "Invalid URI string in DAL: %s" % self.uri
#########################################################
####### Execute code again
#########################################################
####### New error listed below
#########################################################
Traceback (most recent call last):
File "./test_mdb_1.py", line 7, in <module>
db = DAL('mongodb://127.0.0.1:5984/db')
File "/Users/pcode/Desktop/mongodb_test/web2py/gluon/dal.py", line
3724, in __init__
raise RuntimeError, "Failure to connect, tried %d times:\n%s" %
(attempts, error)
RuntimeError: Failure to connect, tried 5 times:
port must be an instance of int
#########################################################
######### Make the following change
#########################################################
Line 3351
FROM:
port = m.group('port') or 27017
TO:
port = 27017
#############################################################################
######### Now the code connects to the server but the error below is
reported
##############################################################################
Traceback (most recent call last):
File "./test_mdb_1.py", line 14, in <module>
Field('number','integer'))
File "/Users/pcode/Desktop/mongodb_test/web2py/gluon/dal.py", line
4032, in define_table
polymodel=polymodel)
File "/Users/pcode/Desktop/mongodb_test/web2py/gluon/dal.py", line
513, in create_table
% dict(length=field.length)
TypeError: unsupported operand type(s) for %: 'type' and 'dict'
#########################################################
####### It is not clear to me why this error is generated
####### So report back to the list
#########################################################
Have fun,
Joe