Ivan
01/29/2025, 1:25 AMproducts
collection.
I have updated my product prices in Supabase and added the necessary decimals.
The reason figuring this out is important is because I have 23,000 products in my products collection and I'll want to be able to update the prices (semi) frequently without updating anything else.
> The intent is to use my main import code with an emplace action to ensure that we add new products as well as update existing products
Appreciate any help! Thanks
===
I am attempting with some test code to update the following product with a new customerPrice: 96.80
because the initial push didn't have 2 decimal places (see Screenshot).
import Typesense from 'typesense';
import dotenv from 'dotenv';
dotenv.config();
const typesense = new Typesense.Client({
nodes: [{
host: process.env.TYPESENSE_HOST!,
port: 443,
protocol: 'https'
}],
apiKey: process.env.NEXT_PUBLIC_TYPESENSE_ADMIN_API_KEY!
});
async function testEmplace() {
const testProduct = {
id: '811659038753', // The product we know exists
customerPrice: 96.80, // The new price we want
};
try {
const response = await typesense
.collections('products')
.documents()
.import([testProduct], { action: 'emplace' });
console.log('Emplace response:', response);
// Verify the update
const updated = await typesense
.collections('products')
.documents(testProduct.id)
.retrieve();
console.log('Updated document:', updated);
} catch (error) {
console.error('Error:', error);
}
}
testEmplace();
Jason Bosco
01/29/2025, 6:23 PM96.8
for customerPrice
in the document screenshot you posted...Jason Bosco
01/29/2025, 6:24 PM96.8
and 96.80
are numerically the same value.
If you send the value as 96.81
then you'll see both decimal places in the document.Ivan
01/29/2025, 6:31 PMJason Bosco
01/29/2025, 6:31 PM