copy method

Future<void> copy(
  1. String id
)

Creates a copy of a document by its ID and inserts it as a new document.

The id should be a valid MongoDB ObjectId string. The copied document will have a new ObjectId assigned.

Implementation

Future<void> copy(String id) async {
  var oid = ObjectId.tryParse(id);
  if (oid != null) {
    var data = await collection.findOne(where.id(oid));
    if (data != null) {
      data.remove('_id');
      await collection.insertOne(data);
    }
  }
}