Is it possible to change the name of the collection?
I want to change the Collection connected to an existing application. I would like to switch to a new Collection by creating a new Collection and then renaming that Collection to the name I am using now.
Hi @ryosek , unfortunately it is not possible to rename a collection once it has been created. You could do it in a few steps, but maybe it would be helpful to understand a bit more about what youâre trying to achieve?
Hello @perry, thank you for answering!
I have an application that allows users to browse the data in the âproduct._default.recordâ collection.
This time, I want to change the user_id stored in âproduct._default.recordâ from a string to a number.
Therefore, I decided to create a new collection âproduct._default.new_recordâ and test that the user_id is successfully changed to a number.
Then, by renaming âproduct._default.recordâ to âproduct._default.old_recordâ and âproduct._default.new_recordâ to âproduct._default.recordâ, the app can connect to the new_record collection.
SELECT META(c).id
FROM mycollection AS c
WHERE tonumber(user_id) IS NULL;
you can store both in same collection and while doing predicate match TO_STR() on both sides
If string NO-OP, number converts to string. (Same as CAST)
WHERE TO_STR(user_id) = TO_STR($user_id)
Also change index.
OR
INSERT INTO old_record( KEY k , VALUE v)
SELECT META(v).id AS k, v
FROM record AS v
WHERE tonumber(user_id) IS NULL;
DELETE FROM record WHERE tonumber(user_id) IS NULL;
UPDATE record AS r
SET user_id = to_number(user_id)
WHERE tonumber(user_id) IS NOT NULL;
@mreiche
Thank you for your reply!
I want to try other table operations on the copied table, so I want to keep a copy.
However, your application might be unhappy that the user_id is a number instead of a string
Why do you think this is unfortunate? The user_id is an auto-incrementing number created by another system, but is currently being imported as a string by mistake, so I am going to change it to a number.
@vsr1
Thank you for your reply!
I could copy table with the query like below.
INSERT INTO product._default.old_record (KEY META(k).id, VALUE k)
SELECT _record AS k
FROM product._default.record AS _record
WHERE tonumber(user_id) IS NULL;
In json number 10 and string â10â are different because value represents actual value and type of value
Say document has {âuser_idâ:10}
WHERE user_id = â10â will not match unless you do TOSTR(user_id) = â10â
I think what @mreiche meant means you might need to change application to reflect this (predicate/ projected values expected string and now changed number)
Correction to your query META(k).id in INSERT part not available , you need to project via SELECT
INSERT INTO product._default.old_record (KEY docid, VALUE k)
SELECT _record AS k, META().id AS docid
FROM product._default.record AS _record
WHERE tonumber(user_id) IS NULL;
@vsr1
I see.
In terms of performance, usability, etc., is it better to keep every value as a string in Couchbase?
I thought it would be a bit redundant to put in to_number() every time I run a query like sort or between.
And thank you for correcting query. This query worked!