MongoDB.live, free & fully virtual. Register Now MongoDB.live, free & fully virtual. Register Now

Migrating app using both Android & .Net SDKs from Realm Cloud to MongoDB Realm

Hi Ian

The migration document looks very useful (essential).

I have a question…

I have a realm on the realm cloud which is accessed by both Android and .Net apps.
They currently both use primary key ids of type Long.
Using MongoDB Realm, I assume I can’t use Android ObjectId because there is no .Net type.

Would the following work

ANDROID:

@PrimaryKey
@Required
var _id: Int = 0

.NET:

[PrimaryKey]
[Required]
[MapTo("_id")]
public int Id { get; set; }

Thanks.

@Richard_Fairall The .NET SDK support ObjectID - see here:
https://developer.mongodb.com/article/realm-database-cascading-deletes#objectids

Thanks Ian, I finally have connection to a MongoDB realm from Android.
Thanks
Richard

Hi Ian
I get the following error on saving a scene
schema for namespace (BookingRealm.Attendance) must include partition key "BookingKey"

BookingKey is the actual partition key.
I’ve tried and scoured documents, but I don’t know how to set the partitionKey in Schema.

Below is a simple example of an offending schema…

{
  "title": "Attendance",
  "bsonType": "object",
  "required": [
    "_id",
    "_partition"
  ],
  "properties": {
    "_id": {
       "bsonType": "int"
     },
     "_partition": {
       "bsonType": "string"
     },
    "visitId": {
      "bsonType": "int"
    },
   }
}

I don’t see BookingKey as a field in your document schema? It needs to be present in the document data model itself

Hi
I’m Android and Windows.
I changed the names for the post. It’s Bookarama
*It needs to be present in the document data model itself…

So in my data model…
public class Zone : RealmObject, PlaceIf
{
[PrimaryKey]
[MapTo("_id")]
public int Id { get; set; }

    [MapTo("_partition")]
    public string _partition { get; set; } = "Bookarama";

…\

Rich

@Richard_Fairall I’ll take a look - could you email me your cloud Realm app URL - the webpage you are viewing for the Realm App? As well as your client side schema? ian.ward@mongodb.com

Realm/io …
private val REALM_INSTANCE = “bookaramasync.de1a.cloud.realm.io
private val REALM_AUTH_URL = “https://$REALM_INSTANCE”;// + “/auth”
private val REALM_URL = “realms://$REALM_INSTANCE”
private val REALM_PATH = REALM_URL + “/bookarama”

When you say ‘client-side schema’ - the only schema I have been involved with here are the ones entered on the Data Access -> Schema page for the Bookarama Realm. I have around 20 classes (Documents) each one has a separate schema. Strangely, some could be ‘Saved’ on the Schema page, others not. Some are currently disfunctional because I had to remove the _id and _partition fields in order to save them! Are these what you need?
btw the Android app is working - I have viewed the data in Realm Studio - all partition keys are set to the Partition Key.

Lets start with URL - can you please email me so I can see what you see? Also, it might be easier to use developer mode in this case since you are migrating to MongoDB Ream - presumable you already have a legacy realm sync app so you just need to switch where you are syncing to and the schema will be set up for you on the server side

Hi

If I can backtrack and create schemas automatically then I will go into Lockdown happy.
Can I please have the URL for me to switch to?

The system is in Developer mode, but I never saw any schemas produced.
I explained below that the Android app is connecting and working.
The Windows app connects but does not sync.
I don’t know what happens to the Schemas I’ve created already ??

Here’s where I’m at for MondoDB,

ANDROID
Created a cluster, linked the realm app.
I cloned entire software for the Realm.io app, modified the connection business and thought life was going to be easy.
The app creates data on the realm ( not all fields are populated) and runs OK.

WINDOWS
I cloned entire software for the Realm.io app (Visual Studio 19), modified the connection business and it connected but did not sync (no schemas - oh those schemas)
Here’s where the problems started.

I started to create Schemas which are clearly incomplete…
It seems that any classes(documents?) which have no data in the realm cannot be saved with the _id and _partition fields.
I have checked the realm created by the Android app and it shows the empty collections.
I sent the realm URL earlier.

It appears that any of the classes (collections) that are in my data model that have not had any data submitted to the Realm (ie empty on RealmStudio) cannot have Schemas with properties _id and _partition, otherwise they cannot be saved. I get the red ink:
schema for namespace (BookaramaRealm.Attendance) must include partition key "Bookarama"