Skip to content

Commit 86b5544

Browse files
committed
Add example for import, update export example
1 parent 04e6b62 commit 86b5544

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Or install it yourself as:
2525

2626
You'll find detailed documentation here: [https://typesense.org/api/](https://typesense.org/api/)
2727

28-
Here are some examples that show you how the Ruby client works: [examples](examples)
28+
Here are some examples with inline comments that walk you through how to use the Ruby client: [examples](examples)
2929

3030
Tests are also a good place to know how the the library works internally: [spec](spec)
3131

examples/collections_and_documents.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,17 @@
210210
]
211211
ap @typesense.collections['companies'].documents.create_many(documents)
212212

213+
## If you already have documents in JSONL format, you can also use #import instead, to avoid the JSON parsing overhead:
214+
# @typesense.collections['companies'].documents.import(documents_in_jsonl_format)
215+
213216
##
214217
# Export all documents in a collection in JSON Lines format
215-
# We use JSON Lines format for performance reasons. You can choose to parse selected lines (elements in the array) as needed.
218+
# We use JSON Lines format for performance reasons. You can choose to parse selected lines as needed, by splitting on \n.
216219
sleep 0.5 # Give Typesense cluster a few hundred ms to create the document on all nodes, before reading it right after (eventually consistent)
217-
array_of_json_strings = @typesense.collections['companies'].documents.export
218-
ap array_of_json_strings
220+
jsonl_data = @typesense.collections['companies'].documents.export
221+
ap jsonl_data
219222

220-
# [
221-
# [0] "{\"company_name\":\"Stark Industries\",\"country\":\"USA\",\"id\":\"124\",\"num_employees\":5215}",
222-
# [1] "{\"company_name\":\"Acme Corp\",\"country\":\"France\",\"id\":\"125\",\"num_employees\":1002}"
223-
# ]
223+
# "{\"company_name\":\"Stark Industries\",\"country\":\"USA\",\"id\":\"124\",\"num_employees\":5215}\n{\"company_name\":\"Acme Corp\",\"country\":\"France\",\"id\":\"125\",\"num_employees\":1002}"
224224

225225
##
226226
# Cleanup

0 commit comments

Comments
 (0)