0

i have following record in algolia

enterprise_name:"manaslu enterprise",
objectID:"14417261",_quotation:[{shamagri_title:"paper ad",price:4000,
unit:"per sq inc",
description:"5*5",
geo_latitude:40,
geo_longitude:89,
type:"service"}
]

i want to add following object to quotation array while quotation collection gets updated.

const enter =  db.collection("quotation").doc("14417261");

  return enter.update({
    shamagri_title: "banner ad",
    rate: 4000,
    unit: "per sq inch",
    description: "15 * 10",
    type: "service",
  });

i have tried to use following code from cloud function to update algolia record

 functions.firestore
  .document("quotation/{quotationId}")

  .onUpdate((change) => {
    const newData = change.after.data();
    const objectID = change.after.id;
    return index.partialUpdateObjects({
      _quotation: {
        _operation: "Add",
        value: newData,
      },
      objectID,
    });
  });

Based on firebase cloud function it does provide objectId based on update i have used above partialUpdateObjects function based on following example from algolia

index.partialUpdateObject({
  _tags: {
    _operation: 'AddUnique',
    value: 'public',
  },
  objectID: 'myID',
})
.then(({ objectIDs }) => {
  console.log(objectIDs);
});

however before i even deploy the cloud function, i get following error

 Argument of type '{ _quotation: { _operation: string; value: FirebaseFirestore.DocumentData; }; objectID: string; }' is not assignable to 
parameter of type 'readonly Record<string, any>[]'.
  Object literal may only specify known properties, and '_quotation' does not exist in type 'readonly Record<string, any>[]'.

19       _quotation: {
         ~~~~~~~~~~~~~
20         _operation: "Add",
   ~~~~~~~~~~~~~~~~~~~~~~~~~~
21         value: newData,
   ~~~~~~~~~~~~~~~~~~~~~~~
22       },
   ~~~~~~~

what might have gone wrong here?

1 Answer 1

1

i got rid of the error by using partialUpdateObject instead of partialUpdateObjects which is used for update for more than one record. in algolia object and objects make huge difference for singular and plural record update

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, if you have found the answer, its a good practice accept your own answer, in this way, the community can identify easily the solution to your question.
I need at least 2days to do so.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.