0

I want to create an application similar to a library.
A little bit of context, I have hundreds of books, and I want to keep a record of what I have, which tome ... I eventually want to create a website and let other people record their collections.

Now for the technical part, I want to use mongoDB because I kinda like the project, I never used a noSQL type database and i like the JSON format. I still didn't look much into the mongoDB doc.

Also, important to remind, I can own many books, and a same book can be owned by many people.

Here is what the database would like(still WIP):

------------------------------------------------
User
------------------------------------------------
+ id
+ first_name
+ first_name
+ mail
+ language
+ etc.
------------------------------------------------

------------------------------------------------
Book
------------------------------------------------
+ id
+ title
+ volume_number
+ edition
+ demographic
+ language
+ condition
+ isbn
+ editor
+ etc.
------------------------------------------------

------------------------------------------------
editor
------------------------------------------------
+ id
+ name
+ etc.
------------------------------------------------

------------------------------------------------
demographic
------------------------------------------------
+ id
+ name
+ etc.
------------------------------------------------

------------------------------------------------
languages
------------------------------------------------
+ id
+ name
+ etc.
------------------------------------------------

------------------------------------------------
authors
------------------------------------------------
+ id
+ first_name
+ first_name
+ etc.
------------------------------------------------

or in JSON like

Now my interrogations:

  • How should I link a book to an user ? The easy way would be to put everything under the user collection, but the thing is if for exemple i have all the Game of Throne books, there is a high possibility other people have the books too, we will repeat the same book x times(they have the same title, isbn, author, etc, everything is the same expect the condition(new, used ...)) for each user. Not sure if it's good.
    The user will also have the possibility to remove a book from his collection, if he sold it for example. I feel like if I put every book under the user document, i can use mongoDB, but if not, I don't know ... Here an example:


var user = {
  id: ObjectId("1"),
  identity: {
      first: "Alan",
      last: "Turing",
      mail:"eichiro.oda@japan.com",
      language: "1"
  },
  collections: [
    mangas: [
      {
        id: ObjectId("2"),
        title: "One Piece",
        volume: 1,
        edition: 5, -> reference to edition document below
        .
        .
        .
        .
      },
      {
        id: ObjectId("3"),
        title: "One Piece",
        volume: 1,
        edition: 6, -> reference to edition document below
        .
        .
        .
        .
      }
    ],
    comics: [
      {
        {
          id: ObjectId("4"),
          title: "Spider-man",
          volume: 1,
          edition: 'Limited',
          .
          .
          .
          .
        },
      }
    ]
  ]
}



var edition = {
  {
    id: ObjectId("5"),
    title: "Collector"
  },
  {
    id: ObjectId("6"),
    title: "Classic"
  }
}

  • Is there another way to do that ? My other thought would be to put everything under the book collection, but i'm not sure how to do it since a user can sell his book.
var book = {
  {
    title: "One Piece",
    volume: 1,
    edition: 6, -> reference to edition document below
    .
    .
    .,
    ownedBy: [
      {
        id: ObjectId("2"),
        identity: {
          first: "Alan",
          last: "Turing",
          mail: "eichiro.oda@japan.com",
          language: "1"
        },
      },
      {
        id: ObjectId("3"),
        identity: {
          first: "Alan",
          last: "Turing",
          mail: "eichiro.oda@japan.com",
          language: "1"
        }
      } 
    ]
  }
}
  • For the book ID, people usually used the ISBN number, but i read on anther stack overflow thread that some books have the same ISBN but aren't the same book

  • Is mongoDB good for what i want to do ? I honestly didn't look into the others databases type, because i wanted to try mongo, but if something more optimized exist, i will go for the optimized version. Note that i really doubt that the database will contains millions/billions of entries.

  • Do you have a schema recommendation ? It's my 1st time creating a database, and I want something who will last long, i don't want to have a recreate it in a few years if possible.

  • Performance side, is there a difference if I put everything under the user document or under the book document ?

Here are some of the threads i found, but they are quite old now =/
Database schema for a library
A library database

Thanks for reading my bad english and thanks for any help you will be able to provide.

VongoSanDi
  • 76
  • 7
  • One of the first thinks to do about schema design is to knowing the relationships between entities - the books and the users. Then, what are the important operations you are performing on this data in your application. These two aspects are common to the database design. MongoDB document based data allows denormalized and flexible data design. I guess this is the advantage you are interested in. It also allows quick development or prototyping. See this documentation for initial guidance about [Introduction to Data Modeling](https://docs.mongodb.com/manual/core/data-modeling-introduction/). – prasad_ Jan 06 '22 at 05:21
  • I read the link, but it still didn't answer my questions.
    – VongoSanDi Jan 06 '22 at 19:58

0 Answers0