Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-1657

db.collection.copyTo is not documented

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • Server_Docs_20231030
    • Affects Version/s: None
    • Component/s: manual
    • Labels:
      None

      I believe this was introduced in 2.1, but I'm not certain.

      > db.foo.copyTo
      function ( newName ){
          return this.getDB().eval(
              function( collName , newName ){
                  var from = db[collName];
                  var to = db[newName];
                  to.ensureIndex( { _id : 1 } );
                  var count = 0;
      
                  var cursor = from.find();
                  while ( cursor.hasNext() ){
                      var o = cursor.next();
                      count++;
                      to.save( o );
                  }
      
                  return count;
              } , this.getName() , newName
          );
      }
      

            Assignee:
            zack.brown@10gen.com Zack Brown
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              10 years, 28 weeks, 6 days ago