Skip to Content
Mastering Flask Web Development - Second Edition
book

Mastering Flask Web Development - Second Edition

by Daniel Gaspar, Jack Stouffer
October 2018
Intermediate to advanced
332 pages
8h 9m
English
Packt Publishing
Content preview from Mastering Flask Web Development - Second Edition

Update

To update objects, the update method is called on the results of a query, as follows:

>>> Post.objects(
        id="5534451d8b84ebf422c2e4c8"
).update(text="Ipsum lorem")

If your query should only return one value, then use update_one to only modify the first result, as follows:

>>> Post.objects(
        id="5534451d8b84ebf422c2e4c8"
).update_one(text="Ipsum lorem")

Unlike traditional SQL, there are many different ways to change a value in MongoDB. Operators are used to change the values of a field in the following different ways:

  • set: Sets a value (same as given earlier)
  • unset: Deletes a value and removes the key
  • inc: Increments a value
  • dec: Decrements a value
  • push: Appends a value to a list
  • push_all: Appends several values to a list
  • pop: Removes ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Flask Web Development, 2nd Edition

Flask Web Development, 2nd Edition

Miguel Grinberg
Flask Web Development

Flask Web Development

Miguel Grinberg

Publisher Resources

ISBN: 9781788995405Supplemental Content