[SERVER-1744] renameCollection "to" param as an array Created: 06/Sep/10  Updated: 06/Dec/22  Resolved: 11/Aug/17

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 1.7.0
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Scott Hernandez (Inactive) Assignee: Backlog - Query Team (Inactive)
Resolution: Won't Fix Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-5768 Swap two collections Closed
Assigned Teams:
Query
Participants:

 Description   

Change renameCollection to support an array of collection names as the destination(s) so that you don't delete the destination collection.

That would support a primary collection with some postfix value (like a number) of "archived" collections. You could do something like this:

{renameCollection:'log", to:["log.1", "log.2"]}

(much like log rotation)

Maybe this would be better as a new command called "moveCollection".



 Comments   
Comment by Eliot Horowitz (Inactive) [ 07/Sep/10 ]

Cursors are invalidated.

This is the kind of stuff db.eval is intended for.
Simple ops you want to do atomically, so not sure it makes sense to add too many helpers.

Comment by Scott Hernandez (Inactive) [ 07/Sep/10 ]

That is just one example. It seems more compelling than my need to basically swap two collections.

I want this change: coll.new -> coll -> coll.old (where only coll.new and coll exist at the beginning)

You are correct, I could do something with an eval.

Does renameCollection currently invalidate cursors on those collections?

Comment by Eliot Horowitz (Inactive) [ 07/Sep/10 ]

will leave open to see if its common

Comment by Eliot Horowitz (Inactive) [ 07/Sep/10 ]

I see, that might be a bit too specific.
You could do it atomically if you use db.eval now

db.eval( function(){
for ( i=6; i>0; i-- ){
rename i to i+ 1
rename log to log1
}

Comment by Scott Hernandez (Inactive) [ 07/Sep/10 ]

log -> log.1
log.1 -> log.2
....

Comment by Eliot Horowitz (Inactive) [ 07/Sep/10 ]

Have to admit I don't understand what you're asking for.
What exactly would

{renameCollection:'log", to:["log.1", "log.2"]}

do

Generated at Thu Feb 08 02:57:54 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.