Fix “index name must be a string” when Dropping Multiple Indexes in MongoDB

If you encounter the “index name must be a string” error when dropping multiple indexes in MongoDB, it’s probably because you’re passing the specifications document instead of the name.

When you use the dropIndexes() method or the dropIndexes command to drop multiple indexes, you need to pass the index names (not the specifications documents) in an array.

Continue reading

Rename a Primary Key in SQL Server (T-SQL)

In SQL Server, you can use the sp_rename stored procedure to rename a user created object in the current database, including a primary key.

This can be handy if you’ve got a primary key that had its name automatically assigned, and you now want to give it a more readable name.

When you create a primary key without explicitly providing a name for it, SQL Server automatically delegates a name for it. Such names typically include a long numeric suffix, which makes it harder to remember. If you need to refer to that primary key (e.g. in your code, documentation, etc), such names can make your life more difficult. Fortunately, sp_rename provides a quick and easy way to change this name.

Continue reading