我可以在 iOS 上使用 MongoDB 作为 CoreData 的替代品吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5172374/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 12:00:01  来源:igfitidea点击:

Can I use MongoDB as a replacement for CoreData on iOS?

iphonecore-datamongodbcouchdbnative

提问by zardon

I'm just starting to read up on NoSQL technologies such as MongoDB and CouchDB. I'm interested in knowing whether I can use MongoDB or indeed any NoSQL technology as a replacement for Core Data applications.

我刚刚开始阅读 NoSQL 技术,例如 MongoDB 和 CouchDB。我很想知道我是否可以使用 MongoDB 或任何 NoSQL 技术来替代 Core Data 应用程序。

Core data applications can take a long time to learn and implement, especially if your app is complex and you just want to do some simple add, edits, deletes and queries (CRUD stuff).

核心数据应用程序可能需要很长时间来学习和实现,特别是如果您的应用程序很复杂并且您只想进行一些简单的添加、编辑、删除和查询(CRUD 内容)。

Because it looks like JSON and looks like it can run really fast; I'm interested in the implementation of NoSQL over Core Data.

因为它看起来像 JSON 并且看起来可以运行得非常快;我对通过核心数据实现 NoSQL 感兴趣。

Can I run MongoDB as native? I did some Google searches but wasn't really able to get the specific answers I'm after.

我可以将 MongoDB 作为本机运行吗?我做了一些谷歌搜索,但并没有真正得到我想要的具体答案。

Such as:

如:

I am not sure what the remit is for NoSQL on iphone platforms, is it supported, would it be denied by the Apple team if I submit an app with NoSQL on it?

我不确定 iPhone 平台上 NoSQL 的职责是什么,它是否受支持,如果我提交一个带有 NoSQL 的应用程序,Apple 团队会拒绝它吗?

Thanks

谢谢

采纳答案by TechZen

As an aside, I will note that it's a common misperception but Core Data is not a database system.

顺便说一句,我会注意到这是一个常见的误解,但 Core Data 不是数据库系统。

Instead, it is a runtime object graph management system with persistent tacked on as option if you want it. It's primary function is to provide the model layer of the Model-View-Controller design pattern. As such, it deals with a lot more than just getting data on and off a disk.

相反,它是一个运行时对象图管理系统,如果需要,可以选择持久化。它的主要功能是提供模型-视图-控制器设计模式的模型层。因此,它处理的不仅仅是从磁盘上获取数据。

Core Data does have a learning curve but in my experience the biggest obstacle many face is trying to treat Core Data as some kind of object oriented wrapper around SQL. From that perspective Core Data is very confusing because it seems to require to learn so much that has nothing to do with persistence.

Core Data 确实有一个学习曲线,但根据我的经验,许多人面临的最大障碍是试图将 Core Data 视为某种围绕 SQL 的面向对象的包装器。从这个角度来看,Core Data 非常令人困惑,因为它似乎需要学习很多与持久性无关的知识。

Using database like SQLite, MongoDB and CouchDB for persistence won't really speed things along at all because, although you might better understand how they get data on and off the disk, they won't help at all in managing the data and the relationship to the other data objects and the objects of the UI. You still have to have a data model and you will have to code all that up by hand. Unless your data model is extremely simple, that will take more time than learning Core Data.

使用 SQLite、MongoDB 和 CouchDB 等数据库进行持久化根本不会真正加快速度,因为尽管您可能会更好地了解它们如何在磁盘上和从磁盘上获取数据,但它们在管理数据和关系方面根本无济于事到其他数据对象和 UI 对象。您仍然必须拥有一个数据模型,并且必须手动编写所有代码。除非你的数据模型非常简单,否则这将比学习 Core Data 花费更多的时间。

The best way to learn Core Data is to ignore the fact that the object graph can be persisted at all. Just start from the perspective that you've got a lot of objects that represent the data model of you app and you have to manage their attributes and relationships.

学习 Core Data 的最好方法是完全忽略对象图可以持久化的事实。刚开始,你有很多代表你应用程序数据模型的对象,你必须管理它们的属性和关系。

回答by John F. Miller

MongoDB is probably not a good fit here. The server assumes that disk space is not a limiting factor. The current stabel brance (1.6.x) does not provide data durability on a single instance. It also uses memory mapped files which are fine on dedicated servers but will cause lots of disk churn and unnecessary memory use on a typical PC. I have no experience with Core Data, but it sounds like a septate niche to me.

MongoDB 可能不适合这里。服务器假定磁盘空间不是限制因素。当前的 stabel brance (1.6.x) 不提供单个实例的数据持久性。它还使用内存映射文件,这些文件在专用服务器上很好,但会在典型的 PC 上导致大量磁盘流失和不必要的内存使用。我没有使用 Core Data 的经验,但对我来说这听起来像是一个独立的利基市场。

回答by Andreas Jung

MongoDB is not designed to be used as an embedded database. It is designed for speed and scalability and unlikely fits the architecture of an embedded OS like IOS. However talking to some MongoDB-backed service in the "cloud" through standard protocols like HTTP/S should not be an issue. You just need to write some web-gateway in front of MongoDB.

MongoDB 并非旨在用作嵌入式数据库。它专为速度和可扩展性而设计,不太适合像 IOS 这样的嵌入式操作系统的架构。然而,通过像 HTTP/S 这样的标准协议在“云”中与某些 MongoDB 支持的服务交谈应该不是问题。你只需要在 MongoDB 前面写一些网络网关。

回答by Travis James

I know that this is a really old question, but I thought I would offer an answer anyway. Couchbase has a suite of software called SyncPoint, which includes TouchDB, which is a build of CouchDB built to run on iOS natively and synchronize itself with any Internet accessible CouchDB instance.

我知道这是一个非常古老的问题,但我想无论如何我都会提供答案。Couchbase 有一套名为 SyncPoint 的软件,其中包括TouchDB,它是 CouchDB 的一个构建版本,用于在 iOS 上本地运行,并与任何 Internet 可访问的 CouchDB 实例同步。

回答by macarthy

CouchDBX http://www.couchone.com/getis a Cocoa application that bundles CouchDB into an OSX app if that is what you are looking for

CouchDBX http://www.couchone.com/get是一个 Cocoa 应用程序,它可以将 CouchDB 捆绑到一个 OSX 应用程序中,如果这是您正在寻找的

回答by Venu Gopal Tewari

MongoDB Mobile is an smaller version of the MongoDB database, optimized to run on mobile and IoT devices.

MongoDB Mobile 是 MongoDB 数据库的较小版本,经过优化可在移动和物联网设备上运行。

MongoDB Mobile comprises two core pieces:

MongoDB Mobile 包含两个核心部分:

A mobile-optimized version of the MongoDB database that runs locally on the device, enabling offline access to data. Native Java (Android) and Swift (iOS) SDKs that manage the lower-level database operations and provide methods to interact with MongoDB Mobile and the Stitch backend.

MongoDB 数据库的移动优化版本,在设备本地运行,支持离线访问数据。本机 Java (Android) 和 Swift (iOS) SDK,用于管理较低级别的数据库操作并提供与 MongoDB Mobile 和 Stitch 后端交互的方法。

https://docs.mongodb.com/stitch/mongodb/mobile/mobile-features/

https://docs.mongodb.com/stitch/mongodb/mobile/mobile-features/

回答by Simon Woodside

Good question. Core Data is tied to schemas and migrations so it's pointless to use it with a NoSQL database.

好问题。核心数据与模式和迁移相关联,因此将其与 NoSQL 数据库一起使用毫无意义。

I haven't tried any of these yet, but there are some claimed solutions out there:

我还没有尝试过这些,但有一些声称的解决方案:

Definitely check those out.

一定要检查这些。

回答by Rincha

For this, I recommend ObjCMongoDB. Is a library for MongoDB and BSON:

为此,我推荐 ObjCMongoDB。是 MongoDB 和 BSON 的库:

https://github.com/paulmelnikow/ObjCMongoDB

https://github.com/paulmelnikow/ObjCMongoDB

Features

特征

  • Simple BSON encoding and decoding, using dictionaries.

  • Built-in support for arrays, dictionaries, embedded objects, strings, numbers, dates, object IDs, and the miscellaneous MongoDB types.

  • More complex encoding and decoding based on NSCoder's keyed coding scheme. A robust delegate interface lets you implement encoding and decoding entirely outside the model classes if necessary.

  • Automatically encodes and decodes Core Data entities. Using the coder's delegate interface you can customize the default behavior, or simply implement alternate behavior it in the entity class.

  • Aims to feel Cocoa-like, not Mongo-like. For example, method names in MongoKeyedPredicate and MongoUpdateRequest are natural in Cocoa, though they don't conform to the underlying Mongo keywords.

  • 使用字典进行简单的 BSON 编码和解码。

  • 对数组、字典、嵌入对象、字符串、数字、日期、对象 ID 和其他 MongoDB 类型的内置支持。

  • 基于 NSCoder 的键控编码方案的更复杂的编码和解码。如果需要,强大的委托接口允许您完全在模型类之外实现编码和解码。

  • 自动编码和解码核心数据实体。使用编码器的委托接口,您可以自定义默认行为,或者只是在实体类中实现替代行为。

  • 旨在让人感觉像可可,而不是像 Mongo。例如,MongoKeyedPredicate 和 MongoUpdateRequest 中的方法名称在 Cocoa 中是自然的,尽管它们不符合底层的 Mongo 关键字。