[web2py] Re: MongoDB testing and development

2011-10-27 Thread Mark Breedveld
Found another error, but I can't figure out an solution.
But it must be rather simple.

I use the following model and without auth ofcourse
if not request.env.web2py_runtime_gae:
## if NOT running on Google App Engine use SQLite or other DB
dbp = DAL('mysql://root:MerMB#2#@192.168.2.29/performance') <--
this one doesn't matter right know
tdb = DAL('mongodb://mb1/db') <-- Connects perfectly, but

tdb.define_table('blog',
Field('name','string'))
tdb.define_table('category',
Field('name',"string"))
tdb.define_table('post',
Field('category',tdb.category),
Field('blog',tdb.blog),
Field('title',"string"),
Field('createdt',"datetime",default=datetime.datetime.now))
tdb.define_table('comment',
Field('content', "text"),
Field('createdt',"datetime",default=datetime.datetime.now))
tdb.define_table('likepost',
Field('likescomment','boolean'),
Field('comment',tdb.comment))
tdb.define_table('postgps',
Field('latitude',"double"),
Field('longitude',"double"),
Field('post',tdb.post))

#Modifications too DAL

def insert(self,table,fields):
ctable = self.connection[table._tablename]
values = dict((k,self.represent(v,table[k].type)) for k,v in
fields) <-- This doesn't work
ctable.insert(values)
return uuid2int(id)

def create_table(self, table, migrate=True, fake_migrate=False,
polymodel=None):
capped=0 # 100 or capped < 1:
"""
#TODO throw new Error that this is an illigal
size?
#http://api.mongodb.org/python/current/api/pymongo/
database.html (create_collection())
If I understood well, then capped collections are
quite limited in size
But they also clean themselves, so maybe we could
implement a general log structure on this type of collections
This part of the method cant't be reached right
now, since we can not implement the capped argument
"""
pass
else:
self.connection.create_collection(table,
size=capped, capped=True)
except CollectionInvalid:
pass
#TODO converted uncapped collection to capped
collection
#create capped tables with a fixed length for performance


Traceback (most recent call last):
  File "/home/beheerder/web2py/gluon/restricted.py", line 204, in
restricted
exec ccode in environment
  File "/home/beheerder/web2py/applications/pt/controllers/
default.py", line 112, in 
  File "/home/beheerder/web2py/gluon/globals.py", line 149, in

self._caller = lambda f: f()
  File "/home/beheerder/web2py/applications/pt/controllers/
default.py", line 73, in add_blog
tdb.blog.insert(name=request.vars.name)
  File "/home/beheerder/web2py/gluon/dal.py", line 5091, in insert
return self._db._adapter.insert(self,self._listify(fields))
  File "/home/beheerder/web2py/gluon/dal.py", line 3754, in insert
values = dict((k,self.represent(v,table[k].type)) for k,v in
fields)
  File "/home/beheerder/web2py/gluon/dal.py", line 3754, in 
values = dict((k,self.represent(v,table[k].type)) for k,v in
fields)
  File "/home/beheerder/web2py/gluon/dal.py", line 4976, in
__getitem__
return dict.__getitem__(self, str(key))
KeyError: 'blog.name'

Any idea? My suggestion is that the fields are not loaded some how,
because of the create function?

On 21 okt, 17:01, Massimo Di Pierro 
wrote:
> yes.
>
> On Oct 21, 2:55 am,MarkBreedveld  wrote:
>
>
>
>
>
>
>
> > Dear Massimo,
>
> > I downloaded the trunk and I am currently testing the MongoDB Adapter
> > and I can tell that inserting currently isn't working. Also the
> > creation of tables doesn't work.
>
> > First question, shall I put the bugs and improvements that I find in
> > the Issue list or just in this discussion?
>
> > Secondly, the create_table method, is it possible to just skip the
> > function with a pass command? Cause collection in mongodb are created
> > on first insert of an document. There are capped collections in
> > MongoDB which offer better performance, but there data size is fixed.
> > My advise would be that by default the model is just passed(if not
> > needed somewhere else in web2py) and we could later implement the
> > capped collections. Because I want to have the adapter working first.
>
> > def create_table(self, table, migrate=True, fake_migrate=False,
> > polymodel=None):
> >         pass
> >                 #May capped collection 
> > here?http://www.mongodb.org/display/DOCS/Capped+Collections
> >                 #because pymongo create collection on first insert 
> > (inserting a
> > document)http://api.mongodb.org/python/2.0/tutorial.html
>
> > RegardsMark,


[web2py] Re: MongoDB testing and development

2011-10-21 Thread Massimo Di Pierro
yes.

On Oct 21, 2:55 am, Mark Breedveld  wrote:
> Dear Massimo,
>
> I downloaded the trunk and I am currently testing the MongoDB Adapter
> and I can tell that inserting currently isn't working. Also the
> creation of tables doesn't work.
>
> First question, shall I put the bugs and improvements that I find in
> the Issue list or just in this discussion?
>
> Secondly, the create_table method, is it possible to just skip the
> function with a pass command? Cause collection in mongodb are created
> on first insert of an document. There are capped collections in
> MongoDB which offer better performance, but there data size is fixed.
> My advise would be that by default the model is just passed(if not
> needed somewhere else in web2py) and we could later implement the
> capped collections. Because I want to have the adapter working first.
>
> def create_table(self, table, migrate=True, fake_migrate=False,
> polymodel=None):
>         pass
>                 #May capped collection 
> here?http://www.mongodb.org/display/DOCS/Capped+Collections
>                 #because pymongo create collection on first insert (inserting 
> a
> document)http://api.mongodb.org/python/2.0/tutorial.html
>
> Regards Mark,