[web2py] Re: MongoDB and list:reference?
update seems to work fine with list:reference as long as the field's value is actually an iterable. I'll do some more testing and make a pull request later. Thanks! On Tuesday, June 4, 2013 2:17:37 PM UTC-4, Alan Etkin wrote: > > By the way, I can get around this by changing this line in >> MongoDBAdapter's insert function in dal.py: >> values[fieldname] = self.object_id(v) >> >> to this: >> if isinstance(v,list): >> values[fieldname] = [self.object_id(x) for x in v] >> else: >> values[fieldname] = self.object_id(v) >> > > I think there's no working implementation available for list:reference > types and MongoDB yet, but your patch looks fine. > BTW: Have you tried calling table.update instead of insert with > list:reference? > Also the insert and update methods could support other types of iterables > as input. > > > > -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] MongoDB and list:reference?
I am having a problem using a list:reference field with a MongoDB database, like so: db.define_table('page', ... Field('id_moderator','list:reference auth_user',default=auth.user_id), ... ) When I insert a record into this table with a list for the id_moderator field, like so: db.page.insert(...,id_moderator=[id_owner],...) I get the error: "object_id argument must be of type ObjectId or an objectid representable integer" because the MongoDBAdapter is not expecting the field's value to be a list. Is this not the correct way to set list:reference type fields? By the way, I can get around this by changing this line in MongoDBAdapter's insert function in dal.py: values[fieldname] = self.object_id(v) to this: if isinstance(v,list): values[fieldname] = [self.object_id(x) for x in v] else: values[fieldname] = self.object_id(v) -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.