How to move a timeseries collection to another db (inside the same MongoDB)?

Hello,

I have an old time series collection called “series”. It is stored in the db “data”. Now, I would like to move this collection to the db “data_old”, as I don’t need it in “data” anymore. First, I tried with the rename command, where one can simply rename from “data.series” to “data_old.series” for standard collections. However, this is not supported for timeseries collections and therefore raises an error (MongoServerError: cannot rename view: data.series).

So my question is what would be the best way to move the timeseries collection from data to data_old? The most stupid way that I can come up with right now is creating a new timeseries collection “series” in data_old and copying all the documents from the one in data to the one in data_old, then deleting the one in data. But is there a faster and more elegant way?

Thanks, best, JZ

Hi @jayzee,

I have the same issue in 5.0.6 and 5.2.0. I can reproduce what you see. I have opened a HELP ticket in the internal MongoDB Jira. I’ll let you know when I get an update.

In the meantime, I think a mongodump of this collection + a mongorestore with a renaming (see options --nsFrom and --nsTo) is probably the best option. Of course this would be faster if you can do that directly on the server to avoid the data transfer over the wire.
–If that’s not possible, then maybe an aggregation with a $out would be the faster approach maybe. I guess this would be faster than the mongodump + mongorestore?

EDIT => I have the answer to this question!

No it wouldn’t be faster because it’s not supported!

Thanks for your patience!
Cheers,
Maxime.

Hey @MaBeuLux88 (yes, it’s myself and I’m now talking to myself!),

You suck and you should read the docs a bit more…
TimeSeries collections actually come with a bunch of restrictions and $out and $merge are one of them!

So please @MaBeuLux88, stop recommending unsupported features in the forum :sweat_smile: !

image

Cheers,
Maxime.

2 Likes

hahahah, love it. dont blame yourself. britney still likes you, even if you make mistakes sometime.

thanks for the advice with mongodump + store, ill look into it and update the post later.

Best, JZ

2 Likes

Saru mo ki kara ochiru

1 Like