Category Archives: Databases

Find and Replace Text in WordPress MySQL Database

In absence of using a WordPress plugin to do this task, it is possible to find every instance of a particular text string within your posts and replace them.

Simply login to your PHPMyAdmin page and input this query:

UPDATE wp_posts SET post_content = REPLACE (post_content, 'TEXT TO REPLACE', 'REPLACEMENT TEXT');

How to search a MongoDB database for entries between two dates or times

So you have a database in MongoDB with a collection. (I presume you know what that all means, otherwise you may be on the wrong page!)

If each of the documents in your collection contains a timestamp, then you can search for all documents between two dates or times. The following example searches for all documents with timestamps between 2pm and 8pm on the 19th Nov 2013:

> db.collection.find({ timestamp: { $gte:ISODate("2013-11-19T14:00:00Z"), $lt: ISODate("2013-11-19T20:00:00Z") } })

This will theĀ timestamp field to have an index, otherwise the result will take a very long time to compute.