Document structure like this:
{
firstObject: {
firstField: "Some value",
secondField: "Some value",
},
secondObject: {
firstField: "Some value",
secondField: "Some value",
}
}
I want to create text index on both objects firstObject
and secondObject
because both object having dynamic fields, I have tried this:
db.collection.createIndex({ firstObject: "text", secondObject: "text" });
But unfortunately this is not working, as per documentation mention, it work on string and array of string:
MongoDB provides text indexes to support text search queries on string content.
text
indexes can include any field whose value is a string or an array of string elements.
Is there any other option to work my scenario? I don’t want to mention each and every object’s field manually in create index because all keys are dynamic.