FTS Index deleted when CollectionDropped

Morning,
If we want to rebuild our collection but already have an FTS index over the top of the collection, how to achieve this? Currently we drop the collection by database.DropCollection(“mycollection”) but found this also drops the FTS index?

Thanks

1 Like

When you drop a collection in MongoDB using database.DropCollection("mycollection"), all indexes associated with that collection are also deleted. Therefore, dropping the collection will also remove the FTS index.

To rebuild the collection without losing the FTS index, you can follow these steps:

  1. Create a backup of the existing collection data and FTS index configuration using the mongodump command. This will create a BSON dump of your data in a specific directory.

  2. Drop the collection using database.DropCollection("mycollection").

  3. Recreate the collection with the desired schema using the database.CreateCollection("mycollection") method.

  4. Create the FTS index again using the database.Collection("mycollection").Indexes.CreateOneAsync method. You can use the IndexKeys.Text method to create a text index on one or more fields.

  5. Restore the data from the backup using the mongorestore command. This will populate the newly created collection with the previous data.

By following these steps, you can rebuild your collection without losing the FTS index. However, note that this process can be time-consuming and resource-intensive, depending on the size of your data. Therefore, it’s important to plan and execute the rebuild process carefully to avoid any potential data loss or downtime.

You made me second guess myself in rechecking if I was correct, and yes I did end up going into a GitHub. io page. How did I get to them? I don’t even have a clue, but the info can be referenced in them but do let me know if you can open them because I’ve never gone to the GitHub version of the MDB website before tonight.

I guess I can’t include the GitHub webpages due to number of link restrictions, but the GitHub website for the C# Driver matches what I’ve said.

Sources:
https://www.mongodb.com/article/mongodb-fts-index-how-to-rebuild-a-collection-without-losing-an-fts-index

1 Like