i didn't understand your question..
This is the complete code
import sys
import time
from gluon.dal import DAL, Field
mongo = DAL('mongodb://localhost:27017/sapo')
mongo.define_table('user',
Field('name', 'text'),
Field('age', 'integer'),
Field('city', 'string')
)
def insert_users():
mongo.user.insert(name='John', age=66, city='Toronto')
mongo.user.insert(name='Mark', age=43, city='Boston')
mongo.user.insert(name='Tom', age=43, city='Detroit')
mongo.user.insert(name='Jim', age=18, city='Detroit')
mongo.user.insert(name='Jack', age=18)
mongo.user.insert(name='Eric', city='Boston')
return 'users in database'
def find_users():
users = mongo(mongo.user.age==18).select()
return dict(users=users)
On Thursday, May 10, 2012 11:58:36 PM UTC+1, Massimo Di Pierro wrote:
>
> What's the model?
>
> On Thursday, 10 May 2012 16:27:51 UTC-5, Francisco Costa wrote:
>>
>> I found another problem!!
>>
>> if you do this:
>> mongo.user.insert(name='Jim', age=18, city='Detroit')
>> mongo.user.insert(name='Jack', age=18)
>>
>> and then select
>> users = mongo(mongo.user.age==18).select()
>>
>> you don't have the field "city" in one of the rows, so you get this error:
>>
>> users = mongo(mongo.user.age==18).select()
>> File "/opt/web2py/gluon/dal.py", line 8123, in select
>> return adapter.select(self.query,fields,attributes)
>> File "/opt/web2py/gluon/dal.py", line 4700, in select
>> return processor(rows,fields,colnames,False)
>> File "/opt/web2py/gluon/dal.py", line 1681, in parse
>> self.parse_value(value, fields[j].type,blob_decode)
>> File "/opt/web2py/gluon/dal.py", line 1575, in parse_value
>> return self.parsemap[key](value,field_type)
>> File "/opt/web2py/gluon/dal.py", line 1641, in parse_id
>> return int(value)
>> ValueError: invalid literal for int() with base 10: 'Jack'
>>
>>
>>
>> On Thursday, May 10, 2012 10:16:32 PM UTC+1, Francisco Costa wrote:
>>>
>>> Just add a '\' at the end of line 4664 and your are done!
>>>
>>> Great job Massimo!
>>>
>>>
>>> On Thursday, May 10, 2012 9:12:48 PM UTC+1, Massimo Di Pierro wrote:
>>>>
>>>> This helps. I have another attempt to fix this in trunk. Hard to test
>>>> it since I do not have mongodb installed.
>>>>
>>>> On Thursday, 10 May 2012 08:39:22 UTC-5, Francisco Costa wrote:
>>>>>
>>>>> Still not working. I think Fields order is wrong.
>>>>>
>>>>> At the end of the select() function I write this:
>>>>>
>>>>> a = []
>>>>> for f in fields:
>>>>> a.append(f.type)
>>>>> return dict(rows=rows, fields=a, colnames=colnames)
>>>>>
>>>>> and I got this:
>>>>>
>>>>> colnames:
>>>>> city
>>>>> age
>>>>> _id
>>>>> name
>>>>> fields:
>>>>> id
>>>>> text
>>>>> integer
>>>>> string
>>>>> rows:
>>>>> Toronto
>>>>> 66L
>>>>> 24652490551171733682233802752L
>>>>> John
>>>>>
>>>>>
>>>>>