Skip to content

Commit 255882e

Browse files
committed
Updated examples
1 parent 29a774a commit 255882e

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

examples/collections_and_documents.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@
167167
# "num_employees" => 5215
168168
# }
169169

170+
# You can also upsert a document, by providing it as an option
171+
# document = @typesense.collections['companies'].documents.create(document, upsert: true)
172+
# ap document
173+
170174
##
171175
# Retrieve a document
172176
sleep 0.5 # Give Typesense cluster a few hundred ms to create the document on all nodes, before reading it right after (eventually consistent)
@@ -180,6 +184,19 @@
180184
# "num_employees" => 5215
181185
# }
182186

187+
##
188+
# Update a document
189+
document = @typesense.collections['companies'].documents['124'].update(
190+
'id' => '124',
191+
'num_employees' => 550
192+
)
193+
ap document
194+
195+
# {
196+
# "id" => "124",
197+
# "num_employees" => 5500
198+
# }
199+
183200
##
184201
# Delete a document
185202
# Deleting a document, returns the document after deletion
@@ -213,6 +230,10 @@
213230
## If you already have documents in JSONL format, you can also use #import instead, to avoid the JSON parsing overhead:
214231
# @typesense.collections['companies'].documents.import(documents_in_jsonl_format)
215232

233+
## You can also bulk upsert documents, by adding an upsert option to #create_many or #import
234+
# @typesense.collections['companies'].documents.create_many(documents, upsert: true)
235+
# @typesense.collections['companies'].documents.import(documents_in_jsonl_format, upsert: true)
236+
216237
##
217238
# Export all documents in a collection in JSON Lines format
218239
# We use JSON Lines format for performance reasons. You can choose to parse selected lines as needed, by splitting on \n.

0 commit comments

Comments
 (0)