Migrating from Stitch to Realm (under iOS and Swift)

Hi there! I’ve just attempted to migrate from Stitch to Realm, under iOS and Swift.

I’m extremely disappointed and frustrated with the process, and also the documentation. There doesn’t seem to be an API guide that matches that of Stitch (there is something but it doesn’t even seem to list all the methods a class defines), and much worse, it looks like now I have to battle all the complexity, quirks, limitations, restrictions, confusing terminology, etc. of Realm, when all I want is to be able to connect to my Atlas cluster, my database and collection, and insert some documents that I defined as Swift structs.

Do I understand correctly that now I have to re-implement my simple and lightweight Swift structs as subclasses of the ‘Object’ type, something bridged from Obj-C; define schema (which I really didn’t want since my struct keeps evolving and changing), and add my objects to the default Realm, before I could insert them into a MongoDB collection on Atlas?

And what does “collection” even mean any more, since Realm seems to redefine the term completely?

What if I really, really, really am not interested in Realm, and especially not in Objective-C, and just want to be able to store Swift structs in MongoDB collections? That’s what I signed up for, that’s why I chose this technology, and it seems that now I have to fight some poorly-integrated chimera of a system in order to accomplish the same thing that used to be so much better and easier before.

Please tell me that I’m missing something, and there’s a way to just do what I was able to do before!

Thanks a lot, and all the best,


Yes you can definitely still query the Atlas collections directly, get the document, and then store them in your swift structs. You do not have to use Realm Sync with their Object class definitions. You can see an example of this here - https://docs.mongodb.com/realm/sdk/ios/examples/mongodb-remote-access/


However, I need to insert records into the collection.

With Stitch, I used to be able to do this:

let itemsCollection = mongoServiceClient.db(“myDatabase”).collection(“myCollection”, withCollectionType: MyStruct.self)

This is what I miss so dearly: the API understanding and working with my Swift structs, without forcing me to map them to new obscure types.

Now I’d need to either convert MyStruct into an Object subclass (an absolute no-go since MyStruct embeds a lot of other structs I’ve defined in the app, and now I’d need to redefine them all as compatible Object subclasses), or to encode MyStruct into JSON and somehow insert it into the collection… except that the (mostly undocumented) API seems to disallow that.

Is there any way to accomplish inserting a Swift struct into an Atlas collection, like we could with Stitch? If not, than this would be a massive regression. While the Apple ecosystem is moving towards Swift and away from Objective-C, you are doing the opposite. There’s also a major trend to use value types (structs) instead of objects, and boom, MongoDB now wants everything to be a class.

I’ve been a paying customer for over a year now, and I chose MongoDB instead of the myriad competitors specifically because it allowed me to insert my structs into a MongoDB instance in the cloud, without too much hassle. This now seems to be gone.

I understand that Realm integration is a strategic goal (pet project) for the company, but if it comes at the cost of removing useful functionalities and making them way more complicated, then I don’t see how MongoDB is to remain competitive in the Apple ecosystem, and I believe some of this old functionality would need to come back ASAP.

My two cents anyway.

@Andras_Puiz I’m not sure if I can be clearer than my previous post but I’ll state it again - you do not need to migrate to Objects and can continue using structs. There is a mongo-client on the Realm SDK that exposes different APIs for you to create, read, update, and delete documents from an Atlas collection, for example -

Thanks again… is there any documentation of public typealias MongoInsertBlock = (Result<AnyBSON, Error>) -> Void?

Once again: we used to be able to add a struct to a collection, and there was a clearly-documented API for that. I would need some more guidance about this API you are proposing.