What is the easiest way to connect MongoDB with Xcode/SwiftUI?

Hello everyone! I’m working on an iOS app whose main functionality is based on its preloaded data, so I’m considering using MongoDB to store this initial data which will be downloaded into CoreData as soon as the app is initialized.

I will use CoreData for the rest of the app’s lifecycle. I just need to store the initial data on the web so I can access it from the app.

I read the documentation and noticed that Swift driver updates are no longer supported, so I’m worried this will present problems in the future. I started following the HabitsApp tutorial that uses Realm, trying to find an easy way to download the database I already created, but the main focus of the app is to use Realm to persist data throughout the lifecycle of the app.

Any ideas? I’m already looking for other database solutions that may provide simpler solutions for what I want to achieve.

Thanks in advance for reading and for any comments.

Welcome to the forums!

The question is a little confusing as it says

and also says

but then says

so… we would need some clarification on that.

Realm (now called Atlas Device SDK) is a direct replacement for CoreData and while CoreData is amazing, Realm may fit the use case even better - and why support two databases when you can do it with one?

When you’re talking about “Swift Driver” updates, that would be different than Realm in that there’s an entire Realm SDK which supports both Swift and SwiftUI so there’s no “driver” component in that context. e.g. You may be overcomplicating it.

I strongly recommend starting with the Installation Guide and then Quick Start and Tutorial. Use a local Realm to get a feel for it - then you can add Sync into the mix. That would enable data to be stored in the cloud (Atlas) which will then sync to the client when it connects. And - will continue to sync with client(s) if you so choose. It becomes your live, offline first cloud sync’d database.

You will likely find Realm to be a great option for a single user local or cloud database as well as supporting authentication and multiple users if that’s the use case.

If you choose to not use the Realm SDK, you can go lower level and interface with Atlas directly using Application Services. Realm is a fantastic interface between Swift and Atlas so I recommend the SDK.

Hello! Thanks for your reply, I really appreciate it!

I can understand the confusion, I’ll clarify now:

  1. When I say that “I’ll use CoreData for the rest of the app’s lifecycle”, it’s because I’m focusing on iOS frameworks. Someone in a group study suggested MongoDB to store the initial content of my app because hard coding it in Xcode has become a boilerplate, but there’s so much to learn about MongoDB that I feel I’m using a bazooka to kill a fly.

  2. When I say “I just need to store the initial data on the web”, it’s because my app has initial data that users need to interact and customize as soon as the app launches. So my plan is to have that data in an online database service (this is where MongoDB came in) and download that info into CoreData for the rest of the functionality (filtering, etc).

  3. When I wrote “the main focus of the app is to use Realm” I was talking about the HabitsApp tutorial. I checked this tutorial to learn more about Realm and to see if I can use it for my app, but again, I’ll persist data using CoreData. I also took a look at this example which uses Vapor and the Swift driver which is “no longer under active development as of 2022”.

I’m new to iOS Development and totally clueless about “hosting” my data model online but I’m sure it’s something I have to do to make my code cleaner and scalable. I’ve never set up an application service before and I’ve only worked with relational databases in the past (a while ago). I feel MongoDB offers way more than I need and it’s better suited for more complex projects and that’s why it’s been so difficult to find the right path to start.

I hope this clarifies a bit where I’m standing.
Thanks again for your time