On Tuesday, May 31, 2016 at 8:12:34 AM UTC-4, arihant daga wrote:
>
> Is there anyway we can use sometihng simmiliar to join in mongodb with 
> web2py. Because web2py gives us this model structure (similar to tables) 
> where i'll have to use related fields but what's the point of using 
> reference fields if i can't perform join. 
>
> So suppose for a simple blog application with web2py and mongodb, do i 
> have to make one model only for storing comments and likes and the body of 
> the post itself ?? or i can have separate models for them and use relation 
> somehow. 
> Please answer and help me with this, becuase i have tried everywhere and 
> not finding the right solution.
>

You can get the record IDs from the first query and then do a second query 
to get the associated records. If you just need the associated comments for 
one or a few posts, you can also take advantage of recursive selects 
<http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Recursive-selects>
 
(which will do an additional query for each post).

MongoDB has introduced the $lookup operator 
<https://docs.mongodb.com/master/reference/operator/aggregation/lookup/#pipe._S_lookup>
 
for left outer joins, but the DAL does not support that.

Note, the DAL was primarily designed for interacting with relational 
databases. It can handle basic interactions with MongoDB, but it does not 
implement all of the MongoDB functionality. Depending on your needs, you 
might be better off using something like PyMongo directly.

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to