Invalid_params error occurred when I try to run JS migration script

I have worked on migrating data from legacy Realm sync from the MongoDB realm for more than two months.

So I followed this migration guide.
This is so hard work.

And I subscribed Atlas Developer support plan and asked how to solve my problems, and I progressed little by little.

But the answers aren’t often enough, and it takes a lot of time to get answers for my questions.
So I want to ask you for help here.

Now I try to run my JS migration script.
But this error occurred at this line.

const user = await Realm.Sync.User.login(‘https://’ + realm_server, creds);.

Error

title: ‘Your request parameters did not validate.’,
status: 400,
code: 601,
invalid_params: [ { name: ‘provider’, reason: “Invalid parameter ‘provider’!” } ]

My username and password are correct because I can log in to Realm Cloud on the web by using them. How can I solve this error? On the internet, I couldn’t find the solution for this. So I want to ask you for help. Thanks in advance.

This is my code. ↓ I omitted uri , username and password and so on here for security reasons.

    const Realm = require('realm');
    const { MongoClient } = require('mongodb');
    const uri = 'mongodb+srv://〇〇〇〇.ufck8.mongodb.net/test';
    const realm_server = '〇〇.us1.cloud.realm.io';
    const username = '〇〇';
    const password = '〇〇';
    const legacy_realm_path = '/〇〇';

    const client = new MongoClient(uri);

    async function run() {
        const creds = Realm.Sync.Credentials.usernamePassword(username, password);
        const user = await Realm.Sync.User.login('https://' + realm_server, creds);
        const config = user.createConfiguration();
        config.sync.fullSynchronization = true;
        config.sync.url = 'realms://' + realm_server + legacy_realm_path;
        config.schema = [TableColumn = {
            name: 'TableColumn',
            primaryKey: '_id',
            properties: {
                _partition: 'string',
                columnScore: 'long',
                createdTime: 'string',
                valid: 'bool',
                isDeleted: 'bool',
                columnName: 'string',
                recordedDate: 'string',
                compoundKey: 'string',
                timestamp: 'date'
            }
        }];

        const realm = await Realm.open(config);
        const allObjects = realm.objects('TableColumn');
        const documents = allObjects.map((obj) => obj.toJSON());
        try {
            await client.connect();
            const database = client.db('〇〇');
            const collection = database.collection('TableColumn');
            await collection.insertMany(documents);
        } finally {
            await client.close();
        }
    }
    run();
1 Like

I solved this problem thanks to MongoDB support.

I solved it like this. ↓

  1. Enabled Username / Password Authentication on my instance.
  2. Created an admin user from Realm Studio and selected the Admin from the dropdown.
2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.