.rename()

Renames a key.

rename(key, newName)

Parameter

Description

key

String

The target key

newName

String

The new name for the key

Returns

Description

The updated data from the provided key's root

db.set('people', ['Peter', 'Henry']);
  
db.rename('people', 'users')); // { users: ['Peter', 'Henry'] };

Also allows the use of dot notation:

db.set('user', { id: 32171, items: ['sword'] });

db.rename('user.items', 'bag'); // { id: 32171, bag: ['sword'] }
db.set('posts', [{ title: 'My #1 post' }]);

db.rename('posts', 'forum.posts'); // { forum: { posts: [{ title: 'My #1 post' }] } } 

Last updated