Start a new topic

Rename Column

Hi,



I want to rename a column in a collection of data stotre. I also want to delete a column in a collection.

Could you please tell how to do that?



Thank you very much!

1 person has this question

Hi Manuel,

One way to do it is export all the data, change it in the csv, then re-upload.

1 person likes this

Same here. How do I rename or delete only one column in a collection. Exporting the data to csv and recreating the collection is not efficient way.

Hello Manuel,


Kinvey uses MongoDB which is a NoSQL database. Unlike relational databases, where data is organized into tables which are defined by a schema (columns and datatypes each column can hold), MongoDB is organized into collections which contain documents in which data organized into key value pairs. Therefore there are no actual columns at all in the data. Each item in a collection consists of field-value pairs ({Field-Name: Field-Value}). 

When you want to rename the field name you need to update all items in the database ("Field-Name" with "New-Field-Name"). 


Therefore the process to follow is:


- Export data to csv/json

- Clear collection data

- Update all items Field-Names

- Import updated collection data from csv/json


With the above process, the _kmd (Kinvey Metadata) which holds the item creation date and last modification date would stay the same.

In addition to Zoheb's earlier comment, I have a few other suggestions:


  • Renaming - Not possible to rename a column from the Kinvey console
  • Deleting - If you want to completely delete a column from any collection, then you will have to delete all the values present in the column which you want to delete from the collection. Once you have an empty column, just go to 'Collection Settings'->'Column Preferences' and click on 'Reset Column Preferences'. The empty column will be deleted from the collection. This suggestion is feasible only when you don't have a lot of data in the column as you have to delete the values manually.
  • Hiding - If there are a lot of columns in a collection and they are bothering you visually, the console gives an option of hiding obsolete columns. Just navigate to collection settings-> column preferences and uncheck the column that you want to hide.


Thanks,

Pranav

Kinvey







1 person likes this
Login or Signup to post a comment