There are several ways to do this. The following should all work:
> db.test.save({_id:1, name:"O'Reilly"})
> db.test.find({name:{$regex:"O'Reilly"}})
{ "_id" : 1, "name" : "O'Reilly" }
> db.test.find({name:{$regex:"O\'Reilly"}})
{ "_id" : 1, "name" : "O'Reilly" }
You can also use the hexadecimal value for the character.
> db.test.find({name:{$regex:"O\x27Reilly"}})
{ "_id" : 1, "name" : "O'Reilly" }
> db.test.find({name:/O\x27Reilly/})
{ "_id" : 1, "name" : "O'Reilly" }
>
There is more information on Regular Expressions on the Advanced
Queries page:
http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-RegularExpressions