CouchDB Document Indexing Issue

TLDR James struggled to index documents from CouchDB, resulting in errors. Kishore Nallan advised checking field definitions and the document's nature. Jason suggested missing "await" statements might cause issues.

Photo of James
James
Wed, 02 Feb 2022 11:05:56 UTC

Hello guys, So I'm getting the doc from my couchdb but the when I try to index if it my collection is doesn't work, does anyone know the cause of this issue?

Photo of Kishore Nallan
Kishore Nallan
Wed, 02 Feb 2022 11:07:25 UTC

Can you please tell me what error you are getting?

Photo of James
James
Wed, 02 Feb 2022 11:29:34 UTC

but x_top is there in the document, here's a gist to the code

Photo of Kishore Nallan
Kishore Nallan
Wed, 02 Feb 2022 11:31:39 UTC

The collection schema defines a `'default_sorting_field': 'x_top'` If you define a default sorting field, that value should always be present in the document. The document you tried to index didn't have this field.

Photo of James
James
Wed, 02 Feb 2022 11:37:57 UTC

it does have

Photo of Kishore Nallan
Kishore Nallan
Wed, 02 Feb 2022 11:39:14 UTC

Can you please try inserting one document outside separately? I'm pretty sure that one of the document is not having that field. You can try catching that exception and printing the value of the document.

Photo of James
James
Wed, 02 Feb 2022 11:43:54 UTC

verified?

Photo of Kishore Nallan
Kishore Nallan
Wed, 02 Feb 2022 11:44:39 UTC

I don't follow you

Photo of James
James
Wed, 02 Feb 2022 11:49:00 UTC

these are the values of the doc

Photo of Kishore Nallan
Kishore Nallan
Wed, 02 Feb 2022 11:51:11 UTC

To unblock, remove the `default_sorting_field` configuration and see if it works.

Photo of James
James
Wed, 02 Feb 2022 11:56:24 UTC

it throws a new error

Photo of Kishore Nallan
Kishore Nallan
Wed, 02 Feb 2022 11:57:45 UTC

Then there is something is certainly wrong in the document you are passing into Typesense, Please look carefully.

Photo of James
James
Wed, 02 Feb 2022 12:02:56 UTC

this is the entire document, can't seem to see anything wrong

Photo of Kishore Nallan
Kishore Nallan
Wed, 02 Feb 2022 12:05:17 UTC

Can you please update this gist() with that data example? I can then try running it.

Photo of James
James
Wed, 02 Feb 2022 12:08:00 UTC

I'm getting the data from my couchdb database

Photo of Jason
Jason
Wed, 02 Feb 2022 16:40:38 UTC

James On a side note, it looks like Lines 121 and 126 are missing "await"

Photo of Jason
Jason
Wed, 02 Feb 2022 16:42:46 UTC

Also, doesn't Line 4 need an await or callback of sorts? I'd imagine `.get` is async, when getting data from couchdb

Photo of Jason
Jason
Wed, 02 Feb 2022 16:44:21 UTC

Essentially, you want to make sure that "doc" is an actual JS object when you console.log it just before sending it to Typesense