I am new to Datastore and I am trying to create a simple app that tracks books borrowing.
I would like the DB schema to be as follows:
books:
book_i
In general this is not a scalable approach: every time a user borrows a book you'd have to re-write both the user
and book
entities, which will get progressively slower as both entities will keep growing.
I'd suggest a different approach: add a new type to your schema, let's call it borrowed_book
, representing a book boorowed by a user:
borrowed_book:
book_id
user_id
timestamp
Now every time a user borrows a book you'd simply create one such borrowed_book
entity, pointing to both the book
and the user
. No changes to the user
or the book
entities. And no nesting required.
Side note: I'd place the firstname
and email
properties under the user
entity type, they don't really belong to the borrowing event where they would be duplicated every time such event occurs for the same user.
Also try to not get confused by the ancestry - it is not required for establishing relationships, see E-commerce Product Categories in Google App Engine (Python)