Skip to content

Commit dd5e608

Browse files
committed
Update remote MongoDB example
1 parent 60ad6f0 commit dd5e608

File tree

10 files changed

+125
-57
lines changed

10 files changed

+125
-57
lines changed

conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@
106106
'guides': ('https://docs.mongodb.com/guides%s', ''),
107107
'java-sdk': ('https://docs.mongodb.com/realm-sdks/java/10.0.0-BETA.8/%s', ''),
108108
'kotlin-sdk': ('https://docs.mongodb.com/realm-sdks/kotlin/10.0.0-BETA.8/%s', ''),
109-
'swift-sdk': ('https://docs.mongodb.com/realm-sdks/swift/10.0.0-beta.6/%s', ''),
110-
'objc-sdk': ('https://docs.mongodb.com/realm-sdks/objc/10.0.0-beta.6/%s', ''),
109+
'swift-sdk': ('https://docs.mongodb.com/realm-sdks/swift/10.0.0-rc.1/%s', ''),
110+
'objc-sdk': ('https://docs.mongodb.com/realm-sdks/objc/10.0.0-rc.1/%s', ''),
111111
'js-sdk': ('https://docs.mongodb.com/realm-sdks/js/latest/%s', ''),
112112
# True External Links
113113
'android': ('https://developer.android.com/%s', ''),
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import XCTest
2+
import RealmSwift
3+
4+
class AccessMongoDB: XCTestCase {
5+
6+
override func setUp() {
7+
let expectation = XCTestExpectation(description: "logs in")
8+
app.login(credentials: Credentials.anonymous) { (user, error) in
9+
guard error == nil else {
10+
fatalError("Login failed: \(error!.localizedDescription)")
11+
}
12+
expectation.fulfill()
13+
}
14+
wait(for: [expectation], timeout: 10)
15+
}
16+
17+
override func tearDown() {
18+
let expectation = XCTestExpectation(description: "logs out")
19+
app.currentUser!.logOut { (error) in
20+
guard error == nil else {
21+
fatalError("Failed to log out: \(error!.localizedDescription)")
22+
}
23+
expectation.fulfill()
24+
}
25+
wait(for: [expectation], timeout: 10)
26+
}
27+
28+
func testRemoteMongoDB() {
29+
let expectation = XCTestExpectation(description: "it completes")
30+
31+
// :code-block-start: remote-mongodb
32+
// mongodb-atlas is the name of cluster service
33+
let client = app.currentUser!.mongoClient("mongodb-atlas")
34+
35+
// Select the database
36+
let database = client.database(named: "tracker")
37+
38+
// Select the collection
39+
let collection = database.collection(withName: "Task")
40+
41+
// Using the user's id to look up tasks
42+
let user = app.currentUser!
43+
let identity = user.id
44+
45+
// Run the query
46+
collection.find(filter: ["_partition": AnyBSON(identity)], { (results, error) in
47+
// Note: this completion handler may be called on a background thread.
48+
// If you intend to operate on the UI, dispatch back to the main
49+
// thread with `DispatchQueue.main.sync {}`.
50+
51+
// Handle errors
52+
guard error == nil else {
53+
print("Call to MongoDB failed: \(error!.localizedDescription)")
54+
// :hide-start:
55+
XCTAssertEqual(error!.localizedDescription, "no rule exists for namespace 'tracker.Task'")
56+
expectation.fulfill()
57+
// :hide-end:
58+
return
59+
}
60+
// Print each document.
61+
print("Results:")
62+
results!.forEach({(document) in
63+
print("Document:")
64+
document.forEach({ (key, value) in
65+
print(" key: \(key), value: \(value)")
66+
})
67+
})
68+
})
69+
// :code-block-end:
70+
wait(for: [expectation], timeout: 10)
71+
}
72+
73+
}

examples/ios/Examples/Authenticate.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
//
2-
// Authenticate.swift
3-
// RealmExamples
4-
//
5-
// Created by Chris Bush on 2020-10-01.
6-
// Copyright © 2020 MongoDB, Inc. All rights reserved.
7-
//
8-
91
import XCTest
102
import RealmSwift
113

examples/ios/RealmExamples.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
48C072042511B5D5004B02BB /* ManageEmailPasswordUsers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48C072032511B5D5004B02BB /* ManageEmailPasswordUsers.swift */; };
2727
48C072062511B6DB004B02BB /* ManageEmailPasswordUsers.m in Sources */ = {isa = PBXBuildFile; fileRef = 48C072052511B6DB004B02BB /* ManageEmailPasswordUsers.m */; };
2828
48E63FB8252646A700F883B1 /* Authenticate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48E63FB7252646A700F883B1 /* Authenticate.swift */; };
29+
48F38B502527806600DDEB65 /* AccessMongoDB.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48F38B4F2527806600DDEB65 /* AccessMongoDB.swift */; };
2930
/* End PBXBuildFile section */
3031

3132
/* Begin PBXContainerItemProxy section */
@@ -65,6 +66,7 @@
6566
48C072032511B5D5004B02BB /* ManageEmailPasswordUsers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ManageEmailPasswordUsers.swift; sourceTree = "<group>"; };
6667
48C072052511B6DB004B02BB /* ManageEmailPasswordUsers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ManageEmailPasswordUsers.m; sourceTree = "<group>"; };
6768
48E63FB7252646A700F883B1 /* Authenticate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Authenticate.swift; sourceTree = "<group>"; };
69+
48F38B4F2527806600DDEB65 /* AccessMongoDB.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccessMongoDB.swift; sourceTree = "<group>"; };
6870
4B040991139BCE878C9D6C0A /* Pods-RealmExamples.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RealmExamples.release.xcconfig"; path = "Target Support Files/Pods-RealmExamples/Pods-RealmExamples.release.xcconfig"; sourceTree = "<group>"; };
6971
68EA0F823D8002EF83FC15E5 /* Pods_RealmSwiftExampleTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RealmSwiftExampleTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
7072
6C55D4D8147A41A52A10E3EF /* Pods_RealmObjcExampleTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RealmObjcExampleTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -128,6 +130,7 @@
128130
48924B8B2514FEFC00CC9567 /* TestSetup.swift */,
129131
48BF341C25111194004139AF /* Task.swift */,
130132
48924B892514EAD900CC9567 /* MultipleUsers.swift */,
133+
48F38B4F2527806600DDEB65 /* AccessMongoDB.swift */,
131134
48924BBA2515309F00CC9567 /* MultipleUsers.m */,
132135
48E63FB7252646A700F883B1 /* Authenticate.swift */,
133136
48BF34172511095C004139AF /* RealmApp.swift */,
@@ -360,6 +363,7 @@
360363
48BF341D25111194004139AF /* Task.swift in Sources */,
361364
48E63FB8252646A700F883B1 /* Authenticate.swift in Sources */,
362365
48924B8A2514EAD900CC9567 /* MultipleUsers.swift in Sources */,
366+
48F38B502527806600DDEB65 /* AccessMongoDB.swift in Sources */,
363367
48BF341F251129AD004139AF /* MyRealmApp.m in Sources */,
364368
48C072042511B5D5004B02BB /* ManageEmailPasswordUsers.swift in Sources */,
365369
);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// mongodb-atlas is the name of cluster service
2+
let client = app.currentUser!.mongoClient("mongodb-atlas")
3+
4+
// Select the database
5+
let database = client.database(named: "tracker")
6+
7+
// Select the collection
8+
let collection = database.collection(withName: "Task")
9+
10+
// Using the user's id to look up tasks
11+
let user = app.currentUser!
12+
let identity = user.id
13+
14+
// Run the query
15+
collection.find(filter: ["_partition": AnyBSON(identity)], { (results, error) in
16+
// Note: this completion handler may be called on a background thread.
17+
// If you intend to operate on the UI, dispatch back to the main
18+
// thread with `DispatchQueue.main.sync {}`.
19+
20+
// Handle errors
21+
guard error == nil else {
22+
print("Call to MongoDB failed: \(error!.localizedDescription)")
23+
return
24+
}
25+
// Print each document.
26+
print("Results:")
27+
results!.forEach({(document) in
28+
print("Document:")
29+
document.forEach({ (key, value) in
30+
print(" key: \(key), value: \(value)")
31+
})
32+
})
33+
})

source/includes/steps-install-cocoapods.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ content: |
2828
Add the line ``use_frameworks!`` if it is not
2929
already there.
3030
31-
Add the line ``pod 'RealmSwift', '=10.0.0-beta.6'`` to your main and test
31+
Add the line ``pod 'RealmSwift', '=10.0.0-rc.1'`` to your main and test
3232
targets.
3333
3434
When done, your Podfile should look something like this:
@@ -43,14 +43,14 @@ content: |
4343
use_frameworks!
4444
4545
# Pods for MyRealmProject
46-
pod 'RealmSwift', '=10.0.0-beta.6'
46+
pod 'RealmSwift', '=10.0.0-rc.1'
4747
4848
end
4949
5050
.. tab::
5151
:tabid: objective-c
5252
53-
Add the line ``pod 'Realm', '=10.0.0-beta.6'`` to your main and test
53+
Add the line ``pod 'Realm', '=10.0.0-rc.1'`` to your main and test
5454
targets.
5555
5656
Add the line ``use_frameworks!`` as well if it is not
@@ -69,12 +69,12 @@ content: |
6969
use_frameworks!
7070
7171
# Pods for MyRealmProject
72-
pod 'Realm', '=10.0.0-beta.6'
72+
pod 'Realm', '=10.0.0-rc.1'
7373
7474
target 'MyRealmProjectTests' do
7575
inherit! :search_paths
7676
# Pods for testing
77-
pod 'Realm', '=10.0.0-beta.6'
77+
pod 'Realm', '=10.0.0-rc.1'
7878
end
7979
8080
end

source/includes/steps-tutorial-ios-swift.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ content: |
4242
4343
- Set the iOS version to 13.0.
4444
- Add the line ``use_frameworks!`` if it is not already there.
45-
- Add the line ``pod 'RealmSwift', '=10.0.0-beta.6'`` to your main target.
45+
- Add the line ``pod 'RealmSwift', '=10.0.0-beta.5'`` to your main target. (Note: tutorial for v10.0.0-rc.1 coming soon.)
4646
4747
When done, your Podfile should look something like this:
4848
@@ -56,7 +56,7 @@ content: |
5656
use_frameworks!
5757
5858
# Pods for TaskTracker
59-
pod 'RealmSwift', '=10.0.0-beta.6'
59+
pod 'RealmSwift', '=10.0.0-beta.5'
6060
6161
end
6262

source/ios.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,5 @@ Reference
140140
:caption: Reference
141141

142142
Auxiliary Files </ios/auxiliary-files>
143-
Objective-C SDK Reference Manual <https://docs.mongodb.com/realm-sdks/objc/10.0.0-beta.6>
144-
Swift SDK Reference Manual <https://docs.mongodb.com/realm-sdks/swift/10.0.0-beta.6>
143+
Objective-C SDK Reference Manual <https://docs.mongodb.com/realm-sdks/objc/10.0.0-rc.1>
144+
Swift SDK Reference Manual <https://docs.mongodb.com/realm-sdks/swift/10.0.0-rc.1>

source/ios/link-identities.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ password. When that user finally decides to create a full account with an SSO
2222
provider or email/password authentication, you need some way of persisting the
2323
user's original anonymous identity with their new permanent identity.
2424

25-
You can link identities using the ``linkUser(with:Credentials)`` method of the
26-
``User`` object of a logged in User.
25+
You can link identities using the ``linkUser(credentials:Credentials)`` method
26+
of the ``User`` object of a logged in User.
2727

2828
.. tabs-realm-languages::
2929

source/ios/remotely-access-mongodb.txt

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -39,39 +39,5 @@ Use the ``MongoClient`` to Query For Data in Your Collection
3939
The following code snippet requires that the user is already
4040
:ref:`authenticated <ios-authenticate>`.
4141

42-
.. code-block:: swift
43-
:emphasize-lines: 15
44-
45-
// mongodb-atlas is the name of cluster service
46-
let client = app.currentUser()!.mongoClient("mongodb-atlas")
47-
48-
// Select the database
49-
let database = client.database(named: "tracker")
50-
51-
// Select the collection
52-
let collection = database.collection(withName: "Task")
53-
54-
// Using the user's id to look up tasks
55-
let user = app.currentUser()!
56-
let identity = user.id!
57-
58-
// Run the query
59-
collection.find(filter: ["_partition": AnyBSON(identity)], { (results, error) in
60-
// Note: this completion handler may be called on a background thread.
61-
// If you intend to operate on the UI, dispatch back to the main
62-
// thread with `DispatchQueue.main.sync {}`.
63-
64-
// Handle errors
65-
guard error == nil else {
66-
print("Call to MongoDB failed: \(error!.localizedDescription)")
67-
return
68-
}
69-
// Print each document.
70-
print("Results:")
71-
results!.forEach({(document) in
72-
print("Document:")
73-
document.forEach({ (key, value) in
74-
print(" key: \(key), value: \(value)")
75-
})
76-
})
77-
})
42+
.. literalinclude:: /examples/generated/code/start/AccessMongoDB.codeblock.remote-mongodb.swift
43+
:language: swift

0 commit comments

Comments
 (0)