I would like query all objects that have a field containing a specific value. For example, I have two documents:
{\"123\": \"apple\", \"217\": \"pear\", \"17
You can use Full-text Index on all fields.
use dbname
db.collectionname.ensureIndex(
{ "$**": "text" },
{ name: "TextIndex" }
)
Then Search Using :
DB db = mongoClient.getDB("dbname");
DBCollection coll = db.getCollection("collectionname");
BasicDBObject query = new BasicDBObject();
query.append("$text", new BasicDBObject("$search", searchstring));
DBCursor cursor = coll.find(query);