It is even more straight forward then that. The result is a list of dict's.
The parsing therefor is not needed. It is simply re-ordering the dict. But
you put the question mark on the right spot. The collections are now equal
to tables, but I not that familiar to python to know how it is done in a
compact and save matter. Cause if a field is empty, then it is not returned
by mongo. Result['fieldname'] would not work. Do result.get('fieldname')
will work, but returns a None value.
I don't want to support sub documents, but maybe later.

There are two questions here.
1. What is the parse function expecting? (you can find it's definition in
baseadapter.parse)

2. What to do with None values, since empty field will not be returned?

regards

Mark,
-----Oorspronkelijk bericht-----
Van: web2py@googlegroups.com [mailto:web2py@googlegroups.com] Namens Alan
Etkin
Verzonden: zondag 4 december 2011 0:36
Aan: web2py-users
Onderwerp: [web2py] Re: Converting mongodb collection to row

When you say that you try to convert a collection to a row, isn't there a
conflict with database systems?

I looking for the first time the mongodb database design, and i assume there
is got to be some sort of mapping of objects:

- A DAL Table is like a Collection
- A DAL Row is (more or less) like a Document
- A DAL Field is like any object stored inside the Document at the root
Document level

As long as there is not more depth in the mongodb object than the described,
the parsing by using a json like simplejson or similar interface should be
straightforward. I think this goes beyond my database skills but i would
like to see the interface implemented if it is available (and shared)
somewhere.

Thanks for your feedback

On Dec 3, 12:35 pm, Mark Breedveld <markbr...@hotmail.com> wrote:
> I'm currently modifing the DAL.py file to get DAL working withmongoDB. 
> I got the insert part working, but the of the select method. So 
> __select is working, but select() ain't. Because I need to convert a 
> pymongo collection to arow. The line I point to has been written by 
> Massimo, but isn't working. I have no idea's at the moment to do this 
> in a general way. The returned value is a dict or a list of dict's, 
> but of course not formatted in a DAL way.
>
> -----Oorspronkelijk bericht-----
> Van: web2py@googlegroups.com [mailto:web2py@googlegroups.com] Namens 
> Alan Etkin
> Verzonden: zaterdag 3 december 2011 17:14
> Aan: web2py-users
> Onderwerp: [web2py] Re: Convertingmongodbcollection torow
>
> Mark, i don't understand your post. Did you modify web2py code? Could 
> you provide a little background on the interface you are working on?
> Thank you
>
> On Nov 30, 10:50 am, Mark Breedveld <m.breedv...@solcon.nl> wrote:
>
>
>
> > I have got the select function ofmongodbadapter working, but know I 
> > need to convert a pymongo cursor torow.
> > The point is the pymongo supports nested documents and that can be a 
> > bit hard to convert for a parameter of the parse method.
>
> > Here is the select function a have ajusted, but this one won't work 
> > with yours because I also altered a lot of other functions. But this 
> > is to get the idea. The line that has to be changed is pointed to 
> > with
> > <--
> >     def select(self,query,fields,attributes):
> >         #if not isinstance(query,Query):
> >         #    raise SyntaxError, "Not Supported"
> >         definition = self._select(query,fields,attributes)
>
> >         ctable = self.connection[str(definition['tablename'])]
> >         if ((definition['sort'] == None) & (definition['skip'] ==
> > None)):
> >             result = ctable.find(definition['query'])
> >         elif((definition['sort'] != None) & (definition['skip'] ==
> > None)):
> >             result =
> > ctable.find(definition['query']).sort(definition['sort'])
> >         elif((definition['sort'] == None) & (definition['skip'] !=
> > None)):
> >             result =
> > ctable.find(definition['query']).skip(definition['skip'])
> >         elif((definition['sort'] != None) & (definition['skip'] !=
> > None)):
> >             result =
> > ctable.find(definition['query']).sort(definition['sort']).skip(defin
> > it
> > ion['skip'])
> >         else:
> >             raise RuntimeError, "No valid query information found"
> >         print str(result)
> >         #rows = [cols['value'] for cols in result] <--- This line 
> > converts the result to be parsed
> >         return self.parse(rows, definition['colnames'], False)
>
> > Anyone with advise on the matter or ideas?
>
> -----
> Geen virus gevonden in dit bericht.
> Gecontroleerd door AVG -www.avg.com
> Versie: 2012.0.1873 / Virusdatabase: 2102/4653 - datum van uitgifte:
> 12/02/11

-----
Geen virus gevonden in dit bericht.
Gecontroleerd door AVG - www.avg.com
Versie: 2012.0.1873 / Virusdatabase: 2102/4654 - datum van uitgifte:
12/03/11

Reply via email to