Copy and paste collections

Copy collections, views, buckets or whole databases in the connection tree and paste them into another database, on the same server or another, with their indexes and validators.

Copy and paste in the connection tree duplicates collections between databases and servers. Copy puts only the names on the clipboard, never the documents. Paste recreates each collection on the target with its options (capped, collation, schema validator, a view’s pipeline) and its indexes, then streams the documents in batches as one job in the Operations pane.

The context menu of a collection in the connection tree

Copy a collection to another server

Example: copy acme_store.products from production to a local test server.

  1. In the tree, select products and press Ctrl+C (or right-click it and choose Copy Collection). Select several collections to copy them together.
  2. On the other connection, select the target database (or its collections folder) and press Ctrl+V (Paste Collections).
  3. If no collection of that name exists on the target, the copy starts at once. Otherwise the Copy Collection dialog asks what to do (next section).

To copy a whole database, right-click it and choose Copy Database, or Copy All Collections/Views/Buckets. Then paste onto another database or a connection. A GridFS bucket is copied with Copy Bucket, which includes its .files and .chunks.

Paste Collections appears in the menus only when the clipboard holds collections.

When the target already exists

The Copy Collection dialog lists the source and target of each collection that already exists. The others are copied as new collections.

Collections Copy ModeEffect
Append to existing target collectionAdds the documents to the existing collection, as the Documents Copy Mode says
Replace existing target collectionDrops the target and copies the source in its place. This asks for confirmation first.
Copy to a new collectionCopies under the New collection name you give
Documents Copy Mode (with Append)Effect on an _id already in the target
Overwrite documents with same _idReplaces the document
Skip documents with existing _idKeeps the target’s document
Insert with new _id if _id existsInserts the copy with a new _id
Always insert with new _idInserts every document with a new _id
Abort if _id already existsStops at the first existing _id; what was copied before stays
OptionDefault
Copy indices from the source collectionOn
Copy the schema validator, if it existsOn

Click Copy Collection to start. A paste never picks a mode by itself. If a target exists and no mode was given (for example from the command line), the paste is refused and nothing is written.

Tips

  • Copying between two databases on the same server is the quickest way to make a scratch copy before you try a reschema or a bulk update.
  • Duplicate Collection in the collection’s context menu makes a copy in the same database in one step.
  • For a copy that keeps only some documents or fields, export to another collection with a query instead (Export data).

Troubleshooting

ProblemWhat to do
Paste is not in the menuThe clipboard holds no collection. Copy again from the tree.
The paste is refusedThe target connection has the read-only lock, or a target exists without a chosen mode.
Append is greyed outViews cannot be appended to, and a collection cannot be appended to itself. Use Copy to a new collection.
The copy stopped partwayThe Operations pane shows the reason for each collection. What was written before the error stays, so check the target before you paste again.