newDocument method

Document newDocument()

Returns a new document with a random identifier.

The current implementations generates a random 128-bit lowercase hexadecimal ID, but this is an implementation detail and could be changed in future.

Example:

database.collection('example').newDocument().insert({'key':'value'});

Implementation

// TODO: Use a more descriptive method name like documentWithRandomId()?
Document newDocument() {
  final random = Random.secure();
  final sb = StringBuffer();
  for (var i = 0; i < 32; i++) {
    sb.write(random.nextInt(16).toRadixString(16));
  }
  return document(sb.toString());
}