I have the following FQL upsert function:
self.client.query(
q.map_(
lambda x: q.if_(
q.exists(
q.match(
q.index(index),
q.select(term1, x),
q.select(term2, x),
q.select(term3, x)
)
),
q.update(q.collection(collection), {'data': x}),
q.create(q.collection(collection), {'data': q.merge(x, insert)})
),
update
)
))
Surprisingly, where it fails is in the update part when a document already exists.
The document does not get updated as one would expect with the Update function (which has a very straightforward and logical intended action).
I have included the entire upsert function above in case that my problem may have something to do with the context of running an update, or perhaps the index structure which has three terms and no values (i.e. all values are returned in the case of a match).
Example:
existing document = {‘term1’: term1, ‘term2’: term2, ‘term3’: term3, ‘tobeupdated’: beforeupdate}
update object = {‘term1’: term1, ‘term2’: term2, ‘term3’: term3, ‘tobeupdated’: afterupdate}
updated document = existing document
Confusingly the response object I get also looks quite non-sensical with mixed up fields from various documents as well as some older fields which were deleted a few days ago.
But I do not see anything unusual happening to the data itself, it is only the response that is scrambled. Except of course that it doesn’t update.
Can anyone see what is wrong here? Thank you.