[英]swift: MongoDB Realm is not syncing to mobile
when the app is opened I try to sync the cloud data to the app using this function打开应用程序时,我尝试使用此 function 将云数据同步到应用程序
struct AppRootView: View {
@State var homeLink = false // <- add here
@State var loginLink = false
@State private var selection: String? = nil
var body: some View {
NavigationView { // <- wrap in the `NavigationView`
VStack(alignment: .leading) {
Text("App")
.bold()
.font(.largeTitle)
NavigationLink(destination: homeMainView(), tag: "home", selection: $selection) {EmptyView()}
NavigationLink(destination: LoginView(), tag: "login", selection: $selection) {EmptyView()}
}
}
.onAppear(perform: handleSignIn)
.frame(minWidth: 0,
maxWidth: .infinity,
minHeight: 0,
maxHeight: .infinity).background(Color.yellow)
}
func handleSignIn() {
print("HANDLING SIGNING IN")
if let _ = app.currentUser() {
print("USER IS LOGGED IN ALREADY")
self.handleRealmSync()
self.selection = "home" // <- activate the `NavigationLink`
} else {
print("USER NEEDS TO LOGIN")
self.selection = "login"
print("not logged in; present sign in/signup view")
}
}
func handleRealmSync(){
let user = app.currentUser()
let partitionValue = "store=walmart"
Realm.asyncOpen(configuration: user!.configuration(partitionValue: partitionValue),
callback: { (maybeRealm, error) in
guard error == nil else {
fatalError("Failed to open realm: \(error!)")
}
guard let realm = maybeRealm else {
fatalError("realm is nil!")
}
// realm opened
print("Realm SYNC IS OPENED")
})
}
}
and I get the print out that "Realm SYNC IS OPENED" but I began to notice that when I query with this code我得到了“Realm SYNC IS OPENED”的打印结果,但我开始注意到当我用这段代码查询时
itemrealm = try! Realm(configuration: user.configuration(partitionValue: partitioningValue)
storeitems = self.itemrealm.objects(Item.self)
the query is not getting all that i have in the cloud cluster.查询没有得到我在云集群中的所有内容。
I guess sync was working well before until I imported more data to the cloud.我猜在我将更多数据导入云之前,同步运行良好。 I currently have atleast 10,000 data in my cluster that are given the partion value being called then I did a.count on storeitems and notice its only pulling about 4,000 items (which is the amount before I imported new data).
我目前在我的集群中有至少 10,000 个数据,这些数据被赋予了被调用的分区值,然后我对 storeitems 进行了 a.count 并注意到它只提取了大约 4,000 个项目(这是我导入新数据之前的数量)。 So the cloud is not syncing the current data.
所以云没有同步当前数据。
I then checked my dashboard log and saw this然后我检查了我的仪表板日志并看到了这个
a clicked on the permission error show this message单击权限错误显示此消息
Error Type: Sync -> SyncSession End Error: Ending session with error: user does not have write access to partition for schema instructions (ProtocolErrorCode=206)
错误类型:同步-> SyncSession 结束错误:以错误结束 session:用户没有对架构指令的分区的写入权限(ProtocolErrorCode=206)
my sync permission is我的同步权限是
Read : true
Write : {
"%%partition": "%%user.id"
}
Users can read all data but can only write their own data用户可以读取所有数据但只能写入自己的数据
How can I fix the permission error and sync my latest cluster to the mobile client?如何修复权限错误并将我的最新集群同步到移动客户端?
when I switched the write permission to当我将写权限切换到
"%%user.id": "%%partition"
this is the error i got这是我得到的错误
Fatal error: Failed to open realm: Error Domain=io.realm.unknown Code=208 "Bad client file identifier (IDENT)" UserInfo={Category=realm::sync::ProtocolError, NSLocalizedDescription=Bad client file identifier (IDENT), Error Code=208}:
致命错误:无法打开 realm:错误域 = io.realm.unknown Code=208 “错误的客户端文件标识符(IDENT)” UserInfo={Category=realm::sync::ProtocolError,NSLocalizedDescription=错误的客户端文件标识符(ID ,错误代码=208}:
Your write permissions are backwards.您的写入权限是向后的。
instead of this (from the question)而不是这个(来自问题)
Read : true
Write : {
"%%partition": "%%user.id"
}
do this做这个
Read : true
Write : {
"%%user.id": "%%partition"
}
The info comes from the MongoDB Realm Sync Documentation Define Sync Rules该信息来自 MongoDB Realm 同步文档定义同步规则
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.