Querying documents

Querying is done using QuerySet as described before in update and delete operations.

Some convenience methods available are:

  • all()
  • count()
  • first()
  • exclude(*fields) to exclude some fields from the result
  • only(*fields) to include only some fields in the result (this can be chained for a union of fields)
  • limit(limit)
  • order_by(ordering)
  • reverse() if we want to reverse the order_by() order
  • skip(number)
  • values() to return Python dict instances instead of model instances

By using raw(), we can use the same queries that we described in the PyMongo section before for querying and still exploit the flexibility and convenience methods provided by the ODM layer.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.146.206.116