我试图了解 mongoDB 的每个元素是如何工作的,但我真的很困惑如何处理离线。
即将:https://realm.io/ https://realm.io/
我读到了这个:
Realm 移动数据库是 Core Data 和 SQLite 的开源、开发人员友好的替代方案。只需几分钟即可启动,几小时内即可移植您的应用程序,并节省数周的工作时间。
然后这部分提到了离线部分:
专为离线使用而设计
这是否意味着Realm可以在移动应用程序中用作完全离线的数据库?
如果我理解正确的话,这个数据库的工作方式与 Android Room 类似,我使用对象/文档存储数据。
因为当我进入“让我们开始”部分时,我被重定向到这里:
https://docs.mongodb.com/realm/get-started/introduction-mobile/ https://docs.mongodb.com/realm/get-started/introduction-mobile/
我在哪里读到这部分:
在开始之前,您需要一个 MongoDB Atlas 帐户。您可以在 Atlas 入门文档中了解有关创建 Atlas 帐户的更多信息
所以我的第一个问题是:为什么我需要 Atlas 帐户?我理解Atlas就是在云端有一个MongoDB数据库。如果我想使用离线数据库,为什么需要这个?
我想本教程想要展示所有工具的协同工作。所以也许可以跳过该步骤。但后来转到 React Native 教程,我看到了这部分:
https://docs.mongodb.com/realm/tutorial/react-native/#std-label-react-native-tutorial https://docs.mongodb.com/realm/tutorial/react-native/#std-label-react-native-tutorial
连接到您的 MongoDB Realm 应用程序
让应用程序与您的后端一起工作,您首先需要实例化 Realm 应用程序。 Realm 应用程序是 MongoDB Realm 后端的接口。导航到 getRealmApp.js 文件并完成 getRealmApp()
这部分代码似乎非常重要:
// Returns the shared instance of the Realm app.
export function getRealmApp() {
if (app === undefined) {
const appId = "<your Realm app ID here>"; // Set Realm app ID here.
const appConfig = {
id: appId,
timeout: 10000,
app: {
name: "default",
version: "0",
},
};
app = new Realm.App(appConfig);
}
return app;
}
该代码迫使我指示我在领域控制台中获得的 AppId。
所以我的第二个问题:如何使这部分离线?我应该跳过 appId 吗?这行得通吗?
这是可能的还是 Realm 真的不适合完全离线工作吗?