algoliasearch-client-javascript icon indicating copy to clipboard operation
algoliasearch-client-javascript copied to clipboard

can `autoGenerateObjectIDIfNotExist` used with `partialUpdateObject` or `partialUpdateObjects`

Open cmgchess opened this issue 3 years ago • 2 comments

In the documentation for partialUpdateObjects it is mentioned autoGenerateObjectIDIfNotExist as a parameter. When I tried to use it throws the error

    const obj = {} //without objectID
    
    index
    .partialUpdateObject(obj, {
    //   createIfNotExists: true,
      autoGenerateObjectIDIfNotExist: true
    }).then((objectID)=>{
        console.log(objectID)
    }).catch((e) => {
        console.log(e)
    })
{
  name: 'ApiError',
  message: 'Invalid object ' +
    'attributes:autoGenerateObjectIDIfNotExist ' +
    'near line:1 column:166',
  status: 400,
  transporterStackTrace: [
    {
      request: [Object],
      response: [Object],
      host: [Object],
      triesLeft: 3
    }
  ]
}

I'm I doing something wrong here Thanks

cmgchess avatar Jun 30 '22 14:06 cmgchess

I checked the code, and think the documentation is wrong, and partialUpdate doesn't support autoGenerate. Note that it's in general not a good idea to have no handle of what the objectID for a record is, as that means you won't be able to update it in the future, and will have to rely on full index updates, which are less efficient

Haroenv avatar Jul 04 '22 09:07 Haroenv

Thanks I was playing around with the API when I stumbled upon this. Thought I did something wrong.

cmgchess avatar Jul 04 '22 10:07 cmgchess