Creating schema for my DB (im new)

I’m new to MongoDB. I’m trying to design my DB but i dont understand if this makes sense.

I have my data currently saved in a json and it is like this: (see end of msg)
Is MongoDB the right DB for me?
When I try to search for a device id it returns me all of the info of that user (query: {“devices.id”: 1} ) and I only wanted to receive the device object.
Note: i have several users and as of now i have my DB organized like this
Thanks in advance

AppDB (Database)
user1@email-com (colection)
user2@email-com (colection)
user3@email-com (colection)

{
  "email": "user1@email-com",
  "name": "user1",
  "password": "",
  "devices": [
    {
      "id": 1,
      "type": "XXX",
      ...
    },
    {
      ...
    },
  ],
  "cards": {
    "pc": [
      [
        {
          "i": "0",
          "x": 0,
          "y": 0,
          "w": 1,
          "h": 2
        },
        {
          ...
        },
      ],
      [
        ...
      ],
    ],
    "mobile": [
      [
        {
          "i": "0",
          "x": 0,
          "y": 0,
          "w": 1,
          "h": 2
        },
        {
          ...
        },
      ]
    ],
    "tablet": [
      ...
    ],
  },
  "notifications": [
    {
      "id": 0,
      "msg": "hello world"
    },
    {
      ...
    },
  ]
}

You don’t want a collection for each user/profile. Create one collection and then each user will be a document inside of it.

So it would be

AppDB

  • users collection
    – user_1
    – user_2
    – user_3

Projection is what you’re looking for, this allows you only to return the fields that you want.

1 Like

Thank you so much i was really lost

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.