In need of help please. I need to un-delete five documents.
I can see the “delete” event…
{
ts: 1600974370490000,
action: "delete",
document: Ref(Collection("Mark"), "264945396321688075"),
data: null
}
But when I try to delete that event using:
Remove(Ref(Collection("Mark"), "264945396321688075"), 1600974370490000, "delete")
I get Error: null is not an object (evaluating ‘n.error’) in the shell.
Any suggestions appreciated. I really need these docs back!
Just tried removing an “update” event on a different document and got the same error. This is in the web shell.
Going to try executing the same FQL directly from my app.
Interesting—I was able to recover my documents via FQL executed directly from my app. I noticed though that my function returned null
and not
An object containing the metadata of the
remove
operations.
as the docs suggest. I guess the error is something to do with the web shell specifically?
Hi @ohawkridge,
Was not able to reproduce the issue you reported:
Paginate(Events(Ref(Collection("Mark"), "264945396321688075")))
{ data:
[ { ts: 1601037233230000,
action: 'create',
document: Ref(Collection("Mark"), "264945396321688075"),
data: { val1: 1 } },
{ ts: 1601037257620000,
action: 'update',
document: Ref(Collection("Mark"), "264945396321688075"),
data: { val2: 2 } },
{ ts: 1601037264462000,
action: 'update',
document: Ref(Collection("Mark"), "264945396321688075"),
data: { val3: 3 } },
{ ts: 1601037267580000,
action: 'update',
document: Ref(Collection("Mark"), "264945396321688075"),
data: { val4: 3 } },
{ ts: 1601037273060000,
action: 'update',
document: Ref(Collection("Mark"), "264945396321688075"),
data: { val4: 4 } },
{ ts: 1601037314800000,
action: 'delete',
document: Ref(Collection("Mark"), "264945396321688075"),
data: null } ] }
>
>
> Remove(Ref(Collection("Mark"), "264945396321688075"), 1601037314800000, "delete")
null
> Paginate(Events(Ref(Collection("Mark"), "264945396321688075")))
{ data:
[ { ts: 1601037233230000,
action: 'create',
document: Ref(Collection("Mark"), "264945396321688075"),
data: { val1: 1 } },
{ ts: 1601037257620000,
action: 'update',
document: Ref(Collection("Mark"), "264945396321688075"),
data: { val2: 2 } },
{ ts: 1601037264462000,
action: 'update',
document: Ref(Collection("Mark"), "264945396321688075"),
data: { val3: 3 } },
{ ts: 1601037267580000,
action: 'update',
document: Ref(Collection("Mark"), "264945396321688075"),
data: { val4: 3 } },
{ ts: 1601037273060000,
action: 'update',
document: Ref(Collection("Mark"), "264945396321688075"),
data: { val4: 4 } } ] }
Do you have more details, I would try to get the same issue and investigate further.
Thanks,
Luigi
Hi @Luigi_Servini, thanks for taking a look.
I’m not sure what else I can tell you. I’ve now tried ‘Remove’ on other events and all of them throw
Error: null is not an object (evaluating 'n.error')
in the web shell. Since the same FQL ran fine outside the web shell the problem must be there? Anything you can suggest to debug further?
Hi @ohawkridge,
Was able to reproduce the issue, but in my case, the delete event is thrown away and document undeleted.
Is the same in your case? May you check?
Luigi
I tried creating a new document and rolling back an update and a delete event.
In both cases, the console gave the same error I mentioned above. However, the document was indeed rolled back and undeleted.
So the action was successful despite the console message.
Cheers for following up.
Console message is little confusing. We got a ticket to address this.
Cool. I got my documents back so I’m happy.
Glad you folks are on it.
Very similar case - I’m trying to Remove a delete event in the web shell.
q.Let(
{
ref: q.Ref(q.Collection("foo"), "258438984686900738"),
delEvent: q.Paginate(q.Events(q.Var("ref")), { before: null, size: 1 }),
exit: q.If(
q.IsEmpty(q.Var("delEvent")),
q.Abort("[safe]Document was not deleted. (01)"),
false
)
},
q.Do(
q.Remove(
q.Var("ref"),
q.Select(["data", 0, "ts"], q.Var("delEvent")),
"delete"
),
"success"
)
)
The above works fine - restores the deleted document, then returns “success”.
However, if I remove the q.Do
part and only return the q.Remove
statement, I get the following failed request:
Error: Cannot read property 'error' of null
The document is still restored though - though when there is an error like this - I would expect no changes in the database?
Hi @aorsten,
You get this error because Remove() on ‘delete’ always returns null.
For improving the readability on that query you can change that way:
Let(
{
ref: Ref(q.Collection("foo"), "258438984686900738"),
delEvent: Select(['data',0],Paginate(Events(Var("ref")), { before: null, size: 1 })),
exit: If(Not(Equals(Select(['action'],Var('delEvent')),'delete')),Abort("[safe]Document was not deleted. (01)"),false),
del: Remove(Var("ref"),Select(["ts"], Var("delEvent")),'delete')
},
If(Not(Equals(Var('delEvent'),Select(['data',0],Paginate(Events(Var("ref")), { before: null, size: 1 })))), "Document removed",Abort("[safe]Document was not deleted. (02)"))
)
I would also hear your feedback on what Remove() on delete should return.
Just wondering if true or false might improve the experience.
Luigi
I suppose that makes sense, but I suppose there’s a bug in the shell then? Shouldn’t I just have received a null response?
I think true would be a better response.
By the way, when I’m working with fauna and get an error from my query I always expect a rollback of all changes in the database during the query. Why doesn’t that happen in this case?
This is a bug in the WebShell
(FrontEnd) to resolve null
and should not be seen in any other drivers including Fauna Shell. This error has got nothing to do with Fauna Query transactionality (rollback).
How does having Do result success
?
That is because Do evaluates expressions sequentially and returns only the results of the last statement.