Thanks for answering me so quickly and the advice. :)

El viernes, 2 de julio de 2021 a las 9:03:39 UTC+1, [email protected] 
escribió:

> It's mostly correct, but it would be better if you went through the public 
> api
>
> state(obj).document
>
> See 
> https://ming.readthedocs.io/en/latest/api/ming.odm.html#ming.odm.base.state
>
> Note by the way, that will grab the document as is in memory, so it won't 
> go through any default or property access side effect that your MappedClass 
> might expose. In theory, if your goal is to convert a mapped object to a 
> dictionary it's better to threat it like any other python object and dump 
> it. If you are using TurboGears, there is for example the 
> tg.util.ming.dictify function that does exactly that. Or you can take 
> inspiration ( 
> https://github.com/TurboGears/tg2/blob/development/tg/util/ming.py#L25-L35 
> )
>
> On Fri, Jul 2, 2021 at 9:54 AM David Santana Gómez <[email protected]> 
> wrote:
>
>>
>> Hello everybody.
>> We want to do a search using ming and from the results obtain the 
>> documents in dictionary format in order to manipulate it or save it in csv.
>> We honestly have not found about this in the documentation and ming only 
>> returns an object in the search.
>> Therefore, we have looked at the code and we *propose* the following to 
>> obtain the dictionary *but we do not know if it is the most optimal or 
>> correct*.
>> We have the following ming object
>> In [8]: full = 
>> BaseGobcanApp.query.find().all()                                             
>>                                           
>>
>>                                                                              
>>                                                          
>> In [9]: 
>> full[0]                                                                      
>>                                                  
>>
>> Out[9]:                                                                      
>>                                                          
>> <BaseGobcanApp 
>> _id=ObjectId('60dc561b8eb792f353c19e24')                                     
>>                                           
>>   _version=1 app_id=524 full_name='PRIVADO' 
>> area_id=12                                                                   
>>                        
>>   servicio='Aplicaciones Corporativas' 
>> servicio_id=4                                                                
>>                   
>>   updated=datetime.datetime(2021, 6, 30, 13, 11, 52, 
>> 961000)                                                                      
>>     
>>   from_full_scrap=True>   
>> And with this command we get its dictionary
>> In [24]: full[0].__ming__.state.document
>> Out[24]:
>> {'_id': ObjectId('60dc561b8eb792f353c19e24'),
>>  '_version': 1,
>>  'app_id': 524,
>>  'area': 'ADMINISTRACIONESPUBLICAS',
>>  'area_id': 12,
>>  'from_full_scrap': True,
>>  'full_name': 'PRIVADO',
>>  'servicio': 'Aplicaciones Corporativas',
>>  'servicio_id': 4,
>>  'updated': datetime.datetime(2021, 6, 30, 13, 11, 52, 961000)}
>> *Questions*:
>>
>>    - This is correct? or is there another way to do it?
>>    
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "TurboGears" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/turbogears/89c8f382-4ed5-4587-9222-03bb61fd4cbcn%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/turbogears/89c8f382-4ed5-4587-9222-03bb61fd4cbcn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/turbogears/cf178ba2-c882-4eaf-bc4b-a78c00217069n%40googlegroups.com.

Reply via email to