Hi there! I'm looking to understand why I can't s...
# community-help
i
Hi there! I'm looking to understand why I can't seem to use the following test code to update a price for a specific product in my
products
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).
Copy code
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();
j
I do see
96.8
for
customerPrice
in the document screenshot you posted...
In Typesense (and most databases), a float data type does not store trailing zeros explicitly. So,
96.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.
❤️ 1
i
Ahh okay! Thanks for the clarification, I didn’t know that. So I can expect that as my main function that I used to create this collection uses emplace, any explicit changes to the prices of existing products from the source DB will update my existing TypeSense product prices.
j
That's correct
1