MongoDB
 sql >> डेटाबेस >  >> NoSQL >> MongoDB

मैं Twitter लेख एग्रीगेटर के लिए MongoDB स्कीमा कैसे डिज़ाइन करूं?

दो सामान्य सुझाव:1.) नकल करने से न डरें। एक ही डेटा को अलग-अलग संग्रह में अलग-अलग स्वरूपित करना अक्सर एक अच्छा विचार है।

2.) यदि आप सामान को क्रमबद्ध और सारांशित करना चाहते हैं, तो यह हर जगह गिनती फ़ील्ड रखने में मदद करता है। mongodb की परमाणु अद्यतन विधि अपर कमांड के साथ गिनना और मौजूदा दस्तावेज़ों में फ़ील्ड जोड़ना आसान बनाती है।

निम्नलिखित निश्चित रूप से त्रुटिपूर्ण है क्योंकि यह मेरे सिर के ऊपर से टाइप किया गया है। लेकिन बिना किसी उदाहरण के बेहतर बुरे उदाहरण मैंने सोचा;)

colletion tweets:

{
  tweetid: 123,
  timeTweeted: 123123234,  //exact time in milliseconds
  dayInMillis: 123412343,  //the day of the tweet kl 00:00:00
  text: 'a tweet with a http://lin.k and an http://u.rl',
  links: [
     'http://lin.k',
     'http://u.rl' 
  ],
  linkCount: 2
}

collection links: 

{
   url: 'http://lin.k'
   totalCount: 17,
   daycounts: {
      1232345543354: 5, //key: the day of the tweet kl 00:00:00
      1234123423442: 2,
      1234354534535: 10
   }
}

नया ट्वीट जोड़ें:

db.x.tweets.insert({...}) //simply insert new document with all fields

//for each found link:
var upsert = true;
var toFind =  { url: '...'};
var updateObj = {'$inc': {'totalCount': 1, 'daycounts.12342342': 1 } }; //12342342 is the day of the tweet
db.x.links.update(toFind, updateObj, upsert);

शीर्ष दस लिंक उनके द्वारा किए गए ट्वीट्स की संख्या के अनुसार क्रमबद्ध करें?

db.x.links.find().sort({'totalCount:-1'}).limit(10);

किसी खास तारीख के लिए सबसे ज़्यादा ट्वीट किया जाने वाला लिंक पाएं?

db.x.links.find({'$gt':{'daycount.123413453':0}}).sort({'daycount.123413453':-1}).limit(1); //123413453 is the day you're after

लिंक के लिए ट्वीट प्राप्त करें?

db.x.tweets.find({'links': 'http://lin.k'});

दस नवीनतम ट्वीट प्राप्त करें?

db.x.tweets.find().sort({'timeTweeted': -1}, -1).limit(10);



  1. Redis
  2.   
  3. MongoDB
  4.   
  5. Memcached
  6.   
  7. HBase
  8.   
  9. CouchDB
  1. Mongo एकत्रीकरण और MongoError:अपवाद:BufBuilder ने 64MB की सीमा से पहले () से 134217728 बाइट्स तक बढ़ने का प्रयास किया

  2. OnBeforeUnload ईवेंट का उपयोग करके ब्राउज़र रीफ़्रेश करें

  3. MongoDB:कुंजी में विशेष वर्णों के साथ हैश पर क्वेरी

  4. कैसे Laravel और MongoDB का उपयोग कर शामिल हुए संग्रह पर मिलान करने के लिए?

  5. सभी mongoosejs में कैसे खोजें?