Skip to content

Conversation

@pdohogne-magento
Copy link
Collaborator

Description

Committing aio app db commands to main

Related Issue

CEXT-5230: Deploy CLI DB App to Staging

Motivation and Context

Release aio app db commands

How Has This Been Tested?

Unit and manual tests, see PRs #12 - #26

Screenshots (if appropriate):

image image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Simran Gulati and others added 30 commits June 25, 2025 18:54
Co-authored-by: Peter Dohogne <pdohogne@adobe.com>
feat:cext-4860 added standalone commands
@nofuss
Copy link
Collaborator

nofuss commented Oct 27, 2025

Part of the reason the collection category is a bit cluttered is because I originally tried to model the syntax on the MongoDB Shell (mongosh). Frankly, tht idea hasn't worked out very well given the context of an aio plugin.

(On the other hand, the syntax of aio-lib-db library is closely modeled on the MongoDB Driver for Node JS, and I think that worked out fairly well. The two libraries are not far from interchangeable and I don't think we should change it.)

So I'd be game for simplifying the db plugin syntax to reduce the clutter. Applying all your suggestions would end up with something like this:

db:

    aio app db ping
    aio app db stats
    aio app db provision
    aio app db status
    aio app db delete
    aio app db show collections

collections (collection or col)

    aio app db collection list [flags]
    aio app db collection create COLLECTION [flags]
    aio app db collection stats COLLECTION
    aio app db collection rename OLDNAME NEWNAME [flags]
    aio app db collection drop COLLECTION

documents (document or doc)

    aio app db document find COLLECTION FILTER [flags]
    aio app db document insert COLLECTION DOCUMENT(S) [flags]
    aio app db document update COLLECTION FILTER UPDATE [flags]
    aio app db document replace COLLECTION FILTER REPLACEMENT [flags]
    aio app db document delete COLLECTION FILTER [flags]
    aio app db document count COLLECTION [flags]

indexes: (index or ind)

    aio app db index create COLLECTION 
    aio app db index drop COLLECTION INDEXNAME
    aio app db index list COLLECTION

My only concern is that it is completely different from the mongosh syntax, but the current syntax of commands isn't much better anyway.

@pdohogne-magento and @moritzraho what do you think?

  1. We don't use camelCase in the commands, we use kebab-case. But in general, when possible one word commands are preferred because faster to type
  2. I see many commands, I know those match the lib 1-1, but I would advocate (we can discuss this of course) for having a few powerful commands instead of many, to reduce the user's mental/discovery load:
  • *One/*Many (e.g. insertOne, insertMany to db insert) => merge + detect based on args (if possible)
  • describe/list/count (e.g. getCollectionInfos, getCollectionNames to db collection list --names) => merge + use flags
  1. suggestion: the collection category is cluttered, should we re-organize commands by splitting index commands out? i.e.:

    • aio app db collection create/rename/drop/..
    • aio app db index create/get/drop
    • (maybe document could also have its own category aio app db document insert/replace/delete/... ?)

@moritzraho
Copy link
Member

moritzraho commented Oct 27, 2025

@nofuss thanks for the review, I agree.

a few points:

  • aliases (edited my previous comment): collection|col index|ind document|doc
  • QUESTION? does it make sense to infer the current collection? so that we don't need to pass COLLECTION as an argument (especially for all the doc commands) we could use a flag instead --collection to overwrite the current one in context. it could be set via an env variable AIO_DB_COLLECTION
  • is aio app db show collections an alias for aio app db collection list?

@nofuss
Copy link
Collaborator

nofuss commented Oct 27, 2025

  • aliases (edited my previous comment): collection|col index|ind document|doc

agreed - collection can get tiring to type

  • QUESTION? does it make sense to infer the current collection? so that we don't need to pass COLLECTION as an argument (especially for all the doc commands) we could use a flag instead --collection to overwrite the current one in context. it could be set via an env variable AIO_DB_COLLECTION

I think this would be a stretch. It would be comparable to having a "current table" in SQL, and that is hard to imagine. I honestly think adding the idea of a "current collection" would be more confusing than convenient.

  • is aio app db show collections an alias for aio app db collection list?

yes. I included show collections mainly because it is so common in mongosh that I can imagine people typing it out of instinct.

@moritzraho
Copy link
Member

I think this would be a stretch. It would be comparable to having a "current table" in SQL, and that is hard to imagine. I honestly think adding the idea of a "current collection" would be more confusing than convenient.

sounds good 🤝

@nofuss
Copy link
Collaborator

nofuss commented Oct 28, 2025

My take on defaults for one vs many document operations:

  • find: default to many
  • all others: default to one (safety first!)

Make sense for everybody?

@moritzraho
Copy link
Member

moritzraho commented Oct 28, 2025

Make sense for everybody?

makes sense, so you would control many insert/deletes/.. through a flag (--many) + multiple args?

@nofuss
Copy link
Collaborator

nofuss commented Oct 28, 2025

Make sense for everybody?

makes sense, so you would control many insert/deletes/.. through a flag (--many) + multiple args?

The --many flag is more about how many documents are affected. Both updateOne and updateMany, for example, have basically the same args, but updateMany will update however many documents are matched by the filter, but updateOne will update one and only one document, even if the filter matches multiple documents.

As for insert, we could make that simpler. If one document is provided, use insertOne, if a list of documents is provided, insertMany (no flag needed).

@pdohogne-magento
Copy link
Collaborator Author

Luckily combining find and findOne just means removing the latter, as finding only a single document can be achieved by passing --limit 1 to the find command 😄

Copy link
Member

@moritzraho moritzraho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleaan!!

lgtm :)
just one small comment

]

DeleteOne.args = {
Delete.args = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this take a many flag?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At Manik's request we are not including deleteMany functionality in the CLI

Copy link
Collaborator

@AjazSumaiya AjazSumaiya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work @pdohogne-magento , looks good

package.json Outdated
{
"name": "@adobe/aio-cli-plugin-app-storage",
"version": "1.1.0",
"version": "1.2.0-alpha.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version should be modified by an explicit release job. We will need to manage the pre version, and the dependency in a branch until we go GA

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants