Skip to content

Commit 511ae70

Browse files
committed
fix(ts): server-side batch import must wrap properties in a DataObject
The TypeScript server-side batching example passed bare objects ({ title }) to data.ingest(). Unlike data.insertMany(), data.ingest() does not treat a bare object as properties on an untyped collection, so under auto-schema it silently imported 5 objects with EMPTY properties (title dropped). Use the DataObject wrapper ({ properties: { title } }) so the property persists, and add a post-example fetchObjects() assertion that fails if the objects or their titles are missing.
1 parent 182965b commit 511ae70

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

_includes/code/howto/manage-data.import.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,11 @@ try {
335335
{
336336
// START ServerSideBatchImportExample
337337
const dataObjects = [
338-
{ title: 'Object 1' },
339-
{ title: 'Object 2' },
340-
{ title: 'Object 3' },
341-
{ title: 'Object 4' },
342-
{ title: 'Object 5' },
338+
{ properties: { title: 'Object 1' } },
339+
{ properties: { title: 'Object 2' } },
340+
{ properties: { title: 'Object 3' } },
341+
{ properties: { title: 'Object 4' } },
342+
{ properties: { title: 'Object 5' } },
343343
]
344344

345345
const myCollection = client.collections.use('MyCollection')
@@ -352,6 +352,14 @@ const result = await myCollection.data.ingest(dataObjects)
352352

353353
console.log(result)
354354
// END ServerSideBatchImportExample
355+
356+
// Verify the import (not shown in the docs snippet): all 5 objects and
357+
// their `title` property must have persisted.
358+
const check = await myCollection.query.fetchObjects({ limit: 5 })
359+
if (check.objects.length !== 5)
360+
throw new Error(`SSB import: expected 5 objects, got ${check.objects.length}`)
361+
if (!check.objects.every((o) => typeof o.properties.title === 'string' && o.properties.title.length > 0))
362+
throw new Error('SSB import did not persist the title property')
355363
}
356364

357365
await client.collections.delete('MyCollection');

0 commit comments

Comments
 (0)