MongoChange.fromJson constructor

MongoChange.fromJson(
  1. Map<String, dynamic> json
)

Creates a MongoChange instance from a raw JSON change payload.

Tries to extract the collection and document ID from either:

  • col
  • ns.coll
  • documentKey._id

Handles optional presence of fullDocument and updateDescription.

Implementation

factory MongoChange.fromJson(Map<String, dynamic> json) {
  return MongoChange(
    operationType: json['operationType'] ?? "update",
    collection: json['col'] ?? json['ns']?['coll'] ?? '',
    documentId:
        json['docId'] ?? json['documentKey']?['_id']?.toString() ?? '',
    doc:
        json['fullDocument'] != null
            ? Map<String, dynamic>.from(json['fullDocument'])
            : null,
    updateDescription:
        json['updateDescription'] != null
            ? Map<String, dynamic>.from(json['updateDescription'])
            : null,
    raw: json,
  );
}