hcengineering/platform · error

Can only move accounts from mongodb for now

Error message

Can only move accounts from mongodb for now

What it means

getMongoAccountDB migrates accounts from an old account DB, but only MongoDB URIs are supported. It checks that the provided uri starts with 'mongodb://' and throws 'Can only move accounts from mongodb for now' for any other scheme (e.g. postgresql://, mysql://, or a typo'd mongo URI).

Source

Thrown at server/account-service/src/migration/utils.ts:25

//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
import { getMongoClient } from '@hcengineering/mongo'

import { MongoAccountDB } from './collections/mongo'

export { MongoAccountDB }

export async function getMongoAccountDB (uri: string, dbNs?: string): Promise<[MongoAccountDB, () => void]> {
  const isMongo = uri.startsWith('mongodb://')

  if (!isMongo) {
    throw new Error('Can only move accounts from mongodb for now')
  }

  const client = getMongoClient(uri)
  const db = (await client.getClient()).db(dbNs ?? 'account')
  const mongoAccount = new MongoAccountDB(db)

  await mongoAccount.init()

  return [
    mongoAccount,
    () => {
      client.close()
    }
  ]
}

export function isShallowEqual (obj1: Record<string, any>, obj2: Record<string, any>): boolean {
  const keys1 = Object.keys(obj1)

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Pass a legacy account DB uri that starts with 'mongodb://'
  2. Note 'mongodb+srv://' fails this check — rewrite it to standard mongodb:// form or fix the check
  3. Verify the env variable/config key holding the OLD account DB uri, not the current one
  4. Add pre-run validation of the uri scheme before starting the migration

Example fix

// before
const db = await getMongoAccountDB(process.env.ACCOUNTS_URI!) // postgresql://...
// after
const legacyUri = process.env.LEGACY_MONGO_ACCOUNTS_URI! // mongodb://...
if (!legacyUri.startsWith('mongodb://')) throw new Error('legacy accounts uri must be mongodb://')
await getMongoAccountDB(legacyUri)
Defensive patterns

Strategy: validation

Validate before calling

function assertMongoUri(uri: string): void {
  if (!uri.startsWith('mongodb://')) {
    throw new Error(`legacy account DB uri must be mongodb:// (got: ${uri.split('://')[0]}://)`)
  }
}

Type guard

function isMongoUri(uri: string): uri is `mongodb://${string}` {
  return uri.startsWith('mongodb://')
}

Try / catch

try {
  const [db, close] = await getMongoAccountDB(uri)
} catch (err) {
  if ((err as Error).message.includes('Can only move accounts from mongodb')) {
    console.error('LEGACY account DB uri is not mongodb:// — check config')
  }
  throw err
}

Prevention

When it happens

Trigger: Calling getMongoAccountDB with a uri that does not start with 'mongodb://' — most commonly a PostgreSQL/other DB connection string passed as the old account DB, or 'mongodb+srv://' (which fails the startsWith check).

Common situations: Account migration script pointed at the new (non-mongo) account store instead of the legacy mongo one; env var (ACCOUNT_DB_URI) set to the wrong service; mongodb+srv cluster URIs not accepted by the prefix check.

Related errors


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/ec2b27696ab55f72. Report an issue: GitHub.