Try the following code:
##################################
#!/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')

db.define_table('m_test',
        Field('name','text'),
        Field('number','integer'))

So a quick check of the current mongoDBAdaptor provides the following error
stream:
#########################################################
##### 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
#########################################################
####### 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
#########################################################

On Wed, May 4, 2011 at 9:24 PM, joseph simpson <jjs0...@gmail.com> wrote:

> OK, I will find some time in the next few days to look at this..
>
> Thanks for your quick response to the question..
>
>
>
>
> On Wed, May 4, 2011 at 8:02 AM, Massimo Di Pierro <
> massimo.dipie...@gmail.com> wrote:
>
>> Please help me try if
>>
>> db=DAL('mongodb://127.0.0.1:5984/db')
>> db.define_table('mytable',...)
>> db.mytable.insert(...)
>>
>> try different field types and let me know which ones fail.
>>
>> works.
>>
>> On May 4, 9:42 am, "David J." <da...@styleflare.com> wrote:
>> > Ahh; Ok;
>> >
>> > Perhaps I will use MongEngine for now and then come back to DAL once we
>> > have time for it;
>> >
>> > I think its not worth your time to build in support for something not so
>> > many people are using;
>> >
>> > Besides anyone can use MongoEngine with Web2py without much difficulty;
>> >
>> > I did some simple tests before just to see; I am going to spend more
>> > time with it now and see what problems I run into;
>> >
>> > Thanks.
>> >
>> > On 5/4/11 10:30 AM, Massimo Di Pierro wrote:
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > > mongodb with DAL does not currently work but, if you help with tests,
>> > > we could make it work
>> >
>> > > On May 4, 8:56 am, "David J."<da...@styleflare.com>  wrote:
>> > >> Is this in trunk;
>> >
>> > >> I will start a new project today and use Mongo For DB
>> >
>> > >> I think I tried it last month and I had some problems; I didnt have
>> the
>> > >> time to look into it.
>> >
>> > >> I will update and try again.
>> >
>> > >> Thanks.
>> >
>> > >> On 5/4/11 9:30 AM, Massimo Di Pierro wrote:
>> >
>> > >>> fixing it now. Looks like not many people testing it. :-)
>> > >>> On May 3, 9:56 pm, joseph simpson<jjs0...@gmail.com>    wrote:
>> > >>>> The current dal.py file contains the following code, between lines
>> > >>>> 3381 and 3404:
>> > >>>> ADAPTERS = {
>> > >>>>       'sqlite': SQLiteAdapter,
>> > >>>>       'sqlite:memory': SQLiteAdapter,
>> > >>>>       'mysql': MySQLAdapter,
>> > >>>>       'postgres': PostgreSQLAdapter,
>> > >>>>       'oracle': OracleAdapter,
>> > >>>>       'mssql': MSSQLAdapter,
>> > >>>>       'mssql2': MSSQL2Adapter,
>> > >>>>       'db2': DB2Adapter,
>> > >>>>       'informix': InformixAdapter,
>> > >>>>       'firebird': FireBirdAdapter,
>> > >>>>       'firebird_embedded': FireBirdAdapter,
>> > >>>>       'ingres': IngresAdapter,
>> > >>>>       'ingresu': IngresUnicodeAdapter,
>> > >>>>       'sapdb': SAPDBAdapter,
>> > >>>>       'jdbc:sqlite': JDBCSQLiteAdapter,
>> > >>>>       'jdbc:sqlite:memory': JDBCSQLiteAdapter,
>> > >>>>       'jdbc:postgres': JDBCPostgreSQLAdapter,
>> > >>>>       'gae': GoogleDatastoreAdapter, # discouraged, for backward
>> > >>>> compatibility
>> > >>>>       'google:datastore': GoogleDatastoreAdapter,
>> > >>>>       'google:sql': GoogleSQLAdapter,
>> > >>>>       'couchdb': CouchDBAdapter,
>> > >>>>       'mongodb': CouchDBAdapter,
>> > >>>> }
>> > >>>> The last line:
>> > >>>>         'mongodb': CouchDBAdapter,
>> > >>>> Maybe should be ---  'mongodb': MongoDBAdapter,
>>
>
>
>
> --
> Joe Simpson
>
> Sent From My DROID!!
>



-- 
Joe Simpson

Sent From My DROID!!

Reply via email to