Skip to content

fix(mongodb): open draft editor dialog on Add Document instead of inserting empty object #923

Description

@ZhuchkaTriplesix

Summary

In MongoDocumentsView, the "Add Document" toolbar button invokes _addDocument():

Future<void> _addDocument() async {
  try {
    await MongoService.instance.insertDocument(
      widget.connection,
      widget.database,
      widget.collection,
      <String, dynamic>{},
    );
    await _load();
  } catch (e) { ... }
}

Clicking "Add Document" instantly creates and persists an empty {} document (with auto-generated _id) directly into the remote collection.

This causes immediate data pollution in production databases, triggers unexpected schema validation failures on collections with JSON Schema validators, and forces the user to manually find and delete or edit the newly created phantom document.

Repro

  1. Open any collection in MongoDocumentsView.
  2. Click the "Add Document" button.
  3. Observe that an empty document is immediately committed to the collection without displaying any draft editor or confirmation modal.

Scope

  • Change "Add Document" to open a document creation dialog or navigate to MongoDocumentEditor with an unsaved draft document template (e.g. {\n \n}).
  • Only execute insertDocument when the user explicitly clicks "Save" or "Insert" in the editor dialog.
  • Validate EJSON syntax before committing the insert to the database.

Out of scope

  • Bulk document import from JSON/CSV files.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions