Skip to content

Commit e37365a

Browse files
(DOCSP-21791) Add Find Steps (#1194)
* add find steps * add find step to qs + tuts * add retrieve step to guide * build error * build error * ja - suggestions
1 parent 5769617 commit e37365a

File tree

37 files changed

+1026
-225
lines changed

37 files changed

+1026
-225
lines changed

source/core/csfle/quick-start.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,45 @@ Procedure
175175
To view the complete code for inserting an encrypted document, see
176176
`our Github repository <{+sample-app-url+}go/local/reader/insert-encrypted-document.go>`__.
177177

178+
.. step:: Retrieve Your Encrypted Document
179+
180+
.. include:: /includes/quick-start/find.rst
181+
182+
.. see:: Complete Code
183+
184+
.. tabs-drivers::
185+
186+
.. tab::
187+
:tabid: java-sync
188+
189+
To view the complete code for finding an encrypted document, see
190+
`our Github repository <{+sample-app-url+}java/local/reader/src/main/java/com/mongodb/csfle/insertEncryptedDocument.java>`__.
191+
192+
.. tab::
193+
:tabid: nodejs
194+
195+
To view the complete code for finding an encrypted document, see
196+
`our Github repository <{+sample-app-url+}node/local/reader/insert_encrypted_document.js>`__.
197+
198+
.. tab::
199+
:tabid: python
200+
201+
To view the complete code for finding an encrypted document, see
202+
`our Github repository <{+sample-app-url+}python/local/reader/insert_encrypted_document.py>`__.
203+
204+
.. tab::
205+
:tabid: csharp
206+
207+
To view the complete code for finding an encrypted document, see
208+
`our Github repository <{+sample-app-url+}dotnet/local/reader/CSFLE/InsertEncryptedDocument.cs>`__
209+
210+
.. tab::
211+
:tabid: go
212+
213+
To view the complete code for finding an encrypted document, see
214+
`our Github repository <{+sample-app-url+}go/local/reader/insert-encrypted-document.go>`__.
215+
216+
178217
Learn More
179218
----------
180219

source/core/csfle/tutorials/aws/aws-automatic.txt

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Create the Application
136136

137137
.. step:: Insert a Document with Encrypted Fields
138138

139-
.. include:: /includes/quick-start/insert.rst
139+
.. include:: /includes/tutorials/automatic/aws/insert.rst
140140

141141
.. see:: Complete Code
142142

@@ -172,6 +172,45 @@ Create the Application
172172
To view the complete code for inserting an encrypted document, see
173173
`our Github repository <{+sample-app-url+}go/aws/reader/insert-encrypted-document.go>`__.
174174

175+
.. step:: Retrieve Your Encrypted Document
176+
177+
.. include:: /includes/tutorials/automatic/aws/find.rst
178+
179+
.. see:: Complete Code
180+
181+
.. tabs-drivers::
182+
183+
.. tab::
184+
:tabid: java-sync
185+
186+
To view the complete code for finding an encrypted document, see
187+
`our Github repository <{+sample-app-url+}java/aws/reader/src/main/java/com/mongodb/csfle/insertEncryptedDocument.java>`__.
188+
189+
.. tab::
190+
:tabid: nodejs
191+
192+
To view the complete code for finding an encrypted document, see
193+
`our Github repository <{+sample-app-url+}node/aws/reader/insert_encrypted_document.js>`__.
194+
195+
.. tab::
196+
:tabid: python
197+
198+
To view the complete code for finding an encrypted document, see
199+
`our Github repository <{+sample-app-url+}python/aws/reader/insert_encrypted_document.py>`__.
200+
201+
.. tab::
202+
:tabid: csharp
203+
204+
To view the complete code for finding an encrypted document, see
205+
`our Github repository <{+sample-app-url+}dotnet/aws/reader/CSFLE/InsertEncryptedDocument.cs>`__
206+
207+
.. tab::
208+
:tabid: go
209+
210+
To view the complete code for finding an encrypted document, see
211+
`our Github repository <{+sample-app-url+}go/aws/reader/insert-encrypted-document.go>`__.
212+
213+
175214
Learn More
176215
----------
177216

source/core/csfle/tutorials/azure/azure-automatic.txt

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Create the Application
134134

135135
.. step:: Insert a Document with Encrypted Fields
136136

137-
.. include:: /includes/quick-start/insert.rst
137+
.. include:: /includes/tutorials/automatic/azure/insert.rst
138138

139139
.. see:: Complete Code
140140

@@ -170,6 +170,45 @@ Create the Application
170170
To view the complete code for inserting an encrypted document, see
171171
`our Github repository <{+sample-app-url+}go/azure/reader/insert-encrypted-document.go>`__.
172172

173+
.. step:: Retrieve Your Encrypted Document
174+
175+
.. include:: /includes/tutorials/automatic/azure/find.rst
176+
177+
.. see:: Complete Code
178+
179+
.. tabs-drivers::
180+
181+
.. tab::
182+
:tabid: java-sync
183+
184+
To view the complete code for finding an encrypted document, see
185+
`our Github repository <{+sample-app-url+}java/azure/reader/src/main/java/com/mongodb/csfle/insertEncryptedDocument.java>`__.
186+
187+
.. tab::
188+
:tabid: nodejs
189+
190+
To view the complete code for finding an encrypted document, see
191+
`our Github repository <{+sample-app-url+}node/azure/reader/insert_encrypted_document.js>`__.
192+
193+
.. tab::
194+
:tabid: python
195+
196+
To view the complete code for finding an encrypted document, see
197+
`our Github repository <{+sample-app-url+}python/azure/reader/insert_encrypted_document.py>`__.
198+
199+
.. tab::
200+
:tabid: csharp
201+
202+
To view the complete code for finding an encrypted document, see
203+
`our Github repository <{+sample-app-url+}dotnet/azure/reader/CSFLE/InsertEncryptedDocument.cs>`__
204+
205+
.. tab::
206+
:tabid: go
207+
208+
To view the complete code for finding an encrypted document, see
209+
`our Github repository <{+sample-app-url+}go/azure/reader/insert-encrypted-document.go>`__.
210+
211+
173212
Learn More
174213
----------
175214

source/core/csfle/tutorials/gcp/gcp-automatic.txt

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ your application to see relevant code samples.
137137

138138
.. step:: Insert a Document with Encrypted Fields
139139

140-
.. include:: /includes/quick-start/insert.rst
140+
.. include:: /includes/tutorials/automatic/gcp/insert.rst
141141

142142
.. see:: Complete Code
143143

@@ -173,6 +173,45 @@ your application to see relevant code samples.
173173
To view the complete code for inserting an encrypted document, see
174174
`our Github repository <{+sample-app-url+}go/gcp/reader/insert-encrypted-document.go>`__.
175175

176+
.. step:: Retrieve Your Encrypted Document
177+
178+
.. include:: /includes/tutorials/automatic/gcp/find.rst
179+
180+
.. see:: Complete Code
181+
182+
.. tabs-drivers::
183+
184+
.. tab::
185+
:tabid: java-sync
186+
187+
To view the complete code for finding an encrypted document, see
188+
`our Github repository <{+sample-app-url+}java/gcp/reader/src/main/java/com/mongodb/csfle/insertEncryptedDocument.java>`__.
189+
190+
.. tab::
191+
:tabid: nodejs
192+
193+
To view the complete code for finding an encrypted document, see
194+
`our Github repository <{+sample-app-url+}node/gcp/reader/insert_encrypted_document.js>`__.
195+
196+
.. tab::
197+
:tabid: python
198+
199+
To view the complete code for finding an encrypted document, see
200+
`our Github repository <{+sample-app-url+}python/gcp/reader/insert_encrypted_document.py>`__.
201+
202+
.. tab::
203+
:tabid: csharp
204+
205+
To view the complete code for finding an encrypted document, see
206+
`our Github repository <{+sample-app-url+}dotnet/gcp/reader/CSFLE/InsertEncryptedDocument.cs>`__
207+
208+
.. tab::
209+
:tabid: go
210+
211+
To view the complete code for finding an encrypted document, see
212+
`our Github repository <{+sample-app-url+}go/gcp/reader/insert-encrypted-document.go>`__.
213+
214+
176215
Learn More
177216
----------
178217

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Finding a document with regular (non-encrypted) client.
2+
3+
{
4+
_id: new ObjectId("629a452e0861b3130887103a"),
5+
name: 'Jon Doe',
6+
ssn: new Binary(Buffer.from("0217482732d8014cdd9ffdd6e2966e5e7910c20697e5f4fa95710aafc9153f0a3dc769c8a132a604b468732ff1f4d8349ded3244b59cbfb41444a210f28b21ea1b6c737508d9d30e8baa30c1d8070c4d5e26", "hex"), 6),
7+
bloodType: new Binary(Buffer.from("0217482732d8014cdd9ffdd6e2966e5e79022e238536dfd8caadb4d7751ac940e0f195addd7e5c67b61022d02faa90283ab69e02303c7e4001d1996128428bf037dea8bbf59fbb20c583cbcff2bf3e2519b4", "hex"), 6),
8+
'key-id': 'demo-data-key',
9+
medicalRecords: new Binary(Buffer.from("0217482732d8014cdd9ffdd6e2966e5e790405163a3207cff175455106f57eef14e5610c49a99bcbd14a7db9c5284e45e3ee30c149354015f941440bf54725d6492fb3b8704bc7c411cff6c868e4e13c58233c3d5ed9593eca4e4d027d76d3705b6d1f3b3c9e2ceee195fd944b553eb27eee69e5e67c338f146f8445995664980bf0", "hex"), 6),
10+
insurance: {
11+
policyNumber: new Binary(Buffer.from("0217482732d8014cdd9ffdd6e2966e5e79108decd85c05be3fec099e015f9d26d9234605dc959cc1a19b63072f7ffda99db38c7b487de0572a03b2139ac3ee163bcc40c8508f366ce92a5dd36e38b3c742f7", "hex"), 6),
12+
provider: 'MaestCare'
13+
}
14+
}
15+
16+
Finding a document with encrypted client, searching on an encrypted field
17+
18+
{
19+
_id: new ObjectId("629a452e0861b3130887103a"),
20+
name: 'Jon Doe',
21+
ssn: 241014209,
22+
bloodType: 'AB+',
23+
'key-id': 'demo-data-key',
24+
medicalRecords: [ { weight: 180, bloodPressure: '120/80' } ],
25+
insurance: { policyNumber: 123142, provider: 'MaestCare' }
26+
}

source/includes/quick-start/find.rst

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
Retrieve the encrypted document you inserted in the
2+
:ref:`Insert a Document with Encrypted Fields <csfle-quick-start-insert>`
3+
step of this guide.
4+
5+
To show the functionality of {+csfle-abbrev+}, the following code snippet queries for
6+
your document with a client configured for automatic {+csfle-abbrev+} as well as
7+
a client that is not configured for automatic {+csfle-abbrev+}.
8+
9+
.. tabs-drivers::
10+
11+
.. tab::
12+
:tabid: java-sync
13+
14+
.. literalinclude:: /includes/sample_apps/csfle/build/java/local/reader/src/main/java/com/mongodb/csfle/insertEncryptedDocument.java
15+
:start-after: start-find
16+
:end-before: end-find
17+
:language: java
18+
:dedent:
19+
:caption: insertEncryptedDocument.java
20+
21+
.. tab::
22+
:tabid: nodejs
23+
24+
.. literalinclude:: /includes/sample_apps/csfle/build/node/local/reader/insert_encrypted_document.js
25+
:start-after: start-find
26+
:end-before: end-find
27+
:language: javascript
28+
:dedent:
29+
:caption: insert_encrypted_document.js
30+
31+
.. tab::
32+
:tabid: python
33+
34+
.. literalinclude:: /includes/sample_apps/csfle/build/python/local/reader/insert_encrypted_document.py
35+
:start-after: start-find
36+
:end-before: end-find
37+
:language: python
38+
:dedent:
39+
:caption: insert_encrypted_document.py
40+
41+
.. tab::
42+
:tabid: csharp
43+
44+
.. literalinclude:: /includes/sample_apps/csfle/build/dotnet/local/reader/CSFLE/InsertEncryptedDocument.cs
45+
:start-after: start-find
46+
:end-before: end-find
47+
:language: csharp
48+
:dedent:
49+
:caption: InsertEncryptedDocument.cs
50+
51+
.. tab::
52+
:tabid: go
53+
54+
.. literalinclude:: /includes/sample_apps/csfle/build/go/local/reader/insert-encrypted-document.go
55+
:start-after: start-find
56+
:end-before: end-find
57+
:language: go
58+
:dedent:
59+
:caption: insert-encrypted-document.go
60+
61+
The output of the preceding code snippet should look like this:
62+
63+
.. literalinclude:: /includes/quick-start/find-output.out
64+
:language: json

source/includes/quick-start/insert.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _csfle-quick-start-insert:
2+
13
Use your {+csfle-abbrev+}-enabled
24
``MongoClient`` instance to insert an encrypted document into the
35
``medicalRecords.patients`` namespace using the following code

source/includes/sample_apps/csfle/build/dotnet/aws/reader/CSFLE/InsertEncryptedDocument.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ public static void Insert()
118118
};
119119
// end-extra-options
120120

121+
var regularClientSettings = MongoClientSettings.FromConnectionString(connectionString);
122+
var regularClient = new MongoClient(regularClientSettings);
123+
var regularCollection = regularClient.GetDatabase(db).GetCollection<BsonDocument>(coll);
124+
121125
// start-client
122126
var clientSettings = MongoClientSettings.FromConnectionString(connectionString);
123127
var autoEncryptionOptions = new AutoEncryptionOptions(
@@ -126,7 +130,7 @@ public static void Insert()
126130
schemaMap: schemaMap,
127131
extraOptions: extraOptions);
128132
clientSettings.AutoEncryptionOptions = autoEncryptionOptions;
129-
var client = new MongoClient(clientSettings);
133+
var secureClient = new MongoClient(clientSettings);
130134
// end-client
131135

132136
// start-insert
@@ -152,14 +156,21 @@ public static void Insert()
152156
};
153157

154158
// Construct an auto-encrypting client
155-
var collection = client.GetDatabase(db).GetCollection<BsonDocument>(coll);
159+
var secureCollection = secureClient.GetDatabase(db).GetCollection<BsonDocument>(coll);
156160

157161
// Insert a document into the collection
158-
collection.InsertOne(sampleDocFields);
159-
var result = collection.Find(FilterDefinition<BsonDocument>.Empty).Limit(1).ToList()[0];
160-
Console.WriteLine("Successfully upserted the sample document!");
161-
Console.WriteLine($"Encrypted client query by the SSN (deterministically-encrypted) field:\n {result}\n");
162+
secureCollection.InsertOne(sampleDocFields);
162163
// end-insert
164+
// start-find
165+
Console.WriteLine("Finding a document with regular (non-encrypted) client.");
166+
var filter = Builders<BsonDocument>.Filter.Eq("name", "Jon Doe");
167+
var regularResult = regularCollection.Find(filter).Limit(1).ToList()[0];
168+
Console.WriteLine($"\n{regularResult}\n");
169+
Console.WriteLine("Finding a document with encrypted client, searching on an encrypted field");
170+
var ssnFilter = Builders<BsonDocument>.Filter.Eq("ssn", 145014000);
171+
var secureResult = secureCollection.Find(ssnFilter).Limit(1).ToList()[0];
172+
Console.WriteLine($"\n{secureResult}\n");
173+
// end-find
163174
}
164175
}
165176
}

0 commit comments

Comments
 (0)