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

मैं Mongoose में डुप्लीकेट दस्तावेज़ों की जाँच कैसे कर सकता हूँ?

यदि आप समान की सूची प्राप्त करना चाहते हैं (_id . को छोड़कर फ़ील्ड, स्पष्ट रूप से) आपके संग्रह में दस्तावेज़, यहां बताया गया है कि आप यह कैसे कर सकते हैं:

collection.aggregate({
    $project: {
        "_id": 1, // keep the _id field where it is anyway
        "doc": "$$ROOT" // store the entire document in the "doc" field
    }
}, {
    $project: {
        "doc._id": 0 // remove the _id from the stored document because we do not want to compare it
    }
}, {
    $group: {
        "_id": "$doc", // group by the entire document's contents as in "compare the whole document"
        "ids": { $push: "$_id" }, // create an array of all IDs that form this group
        "count": { $sum: 1 } // count the number of documents in this group
    }
}, {
    $match: {
        "count": { $gt: 1 } // only show what's duplicated
    }
})

हमेशा की तरह एकत्रीकरण ढांचे के साथ, आप सभी चरणों पर टिप्पणी करके और फिर चरण दर चरण सब कुछ फिर से सक्रिय करके यह समझने की कोशिश कर सकते हैं कि प्रत्येक चरण में वास्तव में क्या चल रहा है।




  1. Redis
  2.   
  3. MongoDB
  4.   
  5. Memcached
  6.   
  7. HBase
  8.   
  9. CouchDB
  1. दिनांक क्वेरी _id के साथ काम करती है लेकिन दिनांक मान के साथ नहीं - MongoDB

  2. mongoDB:$dateToString प्रारूप 15 मिनट के अंतराल से समय दिखाने के लिए

  3. Nodejs UUIDv4 नेवला में उपयोग किए जाने पर निरंतर आईडी मान उत्पन्न करता है

  4. MongoDB - सॉकेट के लिए अनुमति अस्वीकृत:/tmp/mongodb-27017.sock

  5. क्रिप्टो pbkdf2 को mongoDB में कैसे स्टोर करें?