D
D
dvplut2014-10-24 22:10:10
MongoDB
dvplut, 2014-10-24 22:10:10

DB structure for the project?

Hello!
I am slowly learning Mongo. Educational project, news aggregator.
Let's say several rss channels, we take the news for each channel and put it in Mongo, then we show it on the client in a human-readable form.
In view of my little development experience, please tell me how to properly design the database structure for this?
I understand that it should look something like this:
one collection, there are documents

{tit: title, desc: description, items: [{title: title, body: news body, date: pubDate}, {title: title, body: news body, date: pubDate}, ....]}

items - an array of objects, the news itself
But I don't quite understand how I can get these items from there and update them when necessary. Well, you can get it corny find().fetch() then get items from there, but somehow it doesn’t look very good. But with the update, it's a real problem. I looked at $push and $addToSet but did not find how to apply it in my case. I thought perhaps the structure of the database is incorrect.
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Askhat Bikmetov, 2014-10-24
@askhat

MongoDB - flexible scheme data base (which practically means structureless). And you somehow misunderstand the collection - {tit: title, desc: description, items: ...- not a collection, but a document in the collection (news - other documents are embedded in it). It's perfectly fine for crud to use _id: . In general, enjoy all the benefits of the 21st century, especially ODM (ORM for nosql).

A
Alexey Kolosov, 2014-10-25
@satisFUCKtor

Why schemas for a schemaless database? Actually, this is the plus of noSQL solutions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question