MongoDB
 SQL >> Database >  >> NoSQL >> MongoDB

Progettare schema MongoDB per aggregatore di tweet

Due consigli generali:

  1. Non temere la duplicazione: può essere utile salvare gli stessi dati in formati diversi.
  2. Mantieni campi di conteggio per facilitare ordinamenti e somme.

Esempio:

collection tweets: {
  tweetid: 123,
  timeTweeted: 123123234,
  dayInMillis: 123412343,
  text: 'a tweet with a https://lin.k and an https://u.rl',
  links: [ 'https://lin.k', 'https://u.rl' ],
  linkCount: 2
}

collection links: {
  url: 'https://lin.k',
  totalCount: 17,
  daycounts: { 1232345543354: 5 }
}

Per aggiornare i link usa $inc con upsert.

db.x.links.update(
  { url: '...' },
  { $inc: { totalCount: 1, 'daycounts.12342342': 1 } },
  true
);