{"record":{"id":"ec2b27696ab55f72","repo":"hcengineering/platform","slug":"can-only-move-accounts-from-mongodb-for-now","errorCode":null,"errorMessage":"Can only move accounts from mongodb for now","messagePattern":"Can only move accounts from mongodb for now","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/account-service/src/migration/utils.ts","lineNumber":25,"sourceCode":"//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n//\n// See the License for the specific language governing permissions and\n// limitations under the License.\n//\nimport { getMongoClient } from '@hcengineering/mongo'\n\nimport { MongoAccountDB } from './collections/mongo'\n\nexport { MongoAccountDB }\n\nexport async function getMongoAccountDB (uri: string, dbNs?: string): Promise<[MongoAccountDB, () => void]> {\n  const isMongo = uri.startsWith('mongodb://')\n\n  if (!isMongo) {\n    throw new Error('Can only move accounts from mongodb for now')\n  }\n\n  const client = getMongoClient(uri)\n  const db = (await client.getClient()).db(dbNs ?? 'account')\n  const mongoAccount = new MongoAccountDB(db)\n\n  await mongoAccount.init()\n\n  return [\n    mongoAccount,\n    () => {\n      client.close()\n    }\n  ]\n}\n\nexport function isShallowEqual (obj1: Record<string, any>, obj2: Record<string, any>): boolean {\n  const keys1 = Object.keys(obj1)","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/server/account-service/src/migration/utils.ts#L7-L43","documentation":"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).","triggerScenarios":"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).","commonSituations":"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.","solutions":["Pass a legacy account DB uri that starts with 'mongodb://'","Note 'mongodb+srv://' fails this check — rewrite it to standard mongodb:// form or fix the check","Verify the env variable/config key holding the OLD account DB uri, not the current one","Add pre-run validation of the uri scheme before starting the migration"],"exampleFix":"// before\nconst db = await getMongoAccountDB(process.env.ACCOUNTS_URI!) // postgresql://...\n// after\nconst legacyUri = process.env.LEGACY_MONGO_ACCOUNTS_URI! // mongodb://...\nif (!legacyUri.startsWith('mongodb://')) throw new Error('legacy accounts uri must be mongodb://')\nawait getMongoAccountDB(legacyUri)","handlingStrategy":"validation","validationCode":"function assertMongoUri(uri: string): void {\n  if (!uri.startsWith('mongodb://')) {\n    throw new Error(`legacy account DB uri must be mongodb:// (got: ${uri.split('://')[0]}://)`)\n  }\n}","typeGuard":"function isMongoUri(uri: string): uri is `mongodb://${string}` {\n  return uri.startsWith('mongodb://')\n}","tryCatchPattern":"try {\n  const [db, close] = await getMongoAccountDB(uri)\n} catch (err) {\n  if ((err as Error).message.includes('Can only move accounts from mongodb')) {\n    console.error('LEGACY account DB uri is not mongodb:// — check config')\n  }\n  throw err\n}","preventionTips":["Keep the legacy (source) and current (target) account DB uris in separate config keys","Remember mongodb+srv:// does not pass this check — normalize the scheme first","Log the uri scheme (not credentials) at migration start for a fast config check","Add a startup smoke test that calls getMongoAccountDB against a scratch uri"],"tags":["configuration","mongodb","migration","unsupported-uri"],"backgroundTag":"unsupported-database-scheme","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}