I am experimenting with creating a text index in MongoDB for several fields in a sub-document. These fields are not the same from document to document. According to the documentation, I would create a normal text index like so:
db.collection.ensureIndex({
subject: "text",
content: "text"
});
In my case, I want the index on all fields in the fs.files
collection at db.fs.files.metadata
. I've tried this:
db.fs.files.ensureIndex({'metadata.$**': 'text'});
I don't believe this has worked, as searching with db.fs.files.runCommand('text'...
returns zero results, and db.fs.files.stats()
shows the index as a very small size (and I have ~35k documents in this collection).
How can I create a text index on field values of a subdocument where the keys are not known ahead of time?