MongoDB does not free the disk space for OS use after deleting bunch of documents from the collection. We can reclaim that space using following cases. By using compact command - Can be run on collections, but block all orations on database, need small downtime By using repaireDatabase - Run on database need extra space and serious downtime By dumping database and than drop and restore it - Time consuming and need downtime By copy database using temporary name drop original and then re copy with original name - Time consuming and need downtime Following is the best method of achieve same without downtime on replica set Step down secondary server Delete database files Start server, It will start Replica Set Initial Sync. After sync over do the same with other secondary servers one by one For primary server step it down. Make sure one of the secondary become primary Delete database file on primary Start primary server It will start Replica Set Initial Sync. After R
We can use simple $regex to find out documents with specific field have exact word in string value For Example Let's say we have following documents in collection sampledata { _id : ObjectId("583bbccc592818101fb7f3f8"), "textdata" : "This is sample text data", }, { _id : ObjectId("583bbccc592818101fb7e43w"), "textdata" : "data use by default", }, { _id : ObjectId("583bbccc592818101fb723ed"), "textdata" : "bird can fly, This is not always true", } 1 - Now we want only document which have "textdata" contains word "data" db.sampledata.find({ "textdata" : { $regex : /\bdata\b/ }) Above query will return following documents { _id : ObjectId("583bbccc592818101fb7f3f8"), "textdata" : "This is sample text data", }, { _id : ObjectId("583bbccc592818101fb7e43w"), &