Mongo updateOne not failing but not working

I've built a simple first app:

  • display a table of our users

  • when we click on a row in said table, display a radio-button switch. The switch should change a specific value in the selected row.

When I click a row, and then the switch, the query associated with the switch runs fine. It does not show any errors; no error about not being able to connect to the database, no error that it does not have write permissions. It says the query is successful. But, in the query output, it says "modifiedCount: 0", whereas I'd expect it to have a value of 1.

Anyone got a clue what I should look at next to get this resolved?

1 Like

Hello!

It might help to include some screenshots of the build at play here, but I'm initially wondering if the query is getting the appropriate value from the table row and then if the database is actually getting updated. Let us know and our team will get back to you here!

-Justin

Hi @jmann, thanks for responding. As requested, have uploaded three screenshots...

This shows the overall look...

This shows what the query is doing...

This shows the response to the query...

Hi! I'm encountering the same issue. Just following this post. :slightly_smiling_face:

Okay. The issue is that ReTool doesn't support Mongo's classic syntax (where we could do a lookup on _id = "hjfkdashf" and just expect it to understand that it should convert that string to an ObjectId). Instead ReTool uses MongoDB's Extended JSON syntax. This means we have to be explicit about the "_id" string being of type ObjectId, like so...

{ _id: { "$oid" : <your-object-id> } }

when interacting with ObjectId().

That gets me a matchedCount: 1 in the query output.

More deets here >> MongoDB Integration

1 Like

Now I'm just stuck with figuring out how to get the boolean-opposite of a value, ie, if I just want to flip the existing boolean, how do I achieve that?

e.g. in my Update field, what I want is something like...

{ $set: { "active" : {{ !users.data['0'].active }} } }

but the presence of the "!" is not flipping the boolean, as I'd expect in js; instead it's giving me the error message:

The value has to be of type 'object | void', you provided a value of type 'string'

And for those following along at home, the solution to the second question^ was to use tertiary operators, as per...

{ $set: { active : {{ users.data['0'].active ? false : true }} } }

{ $set: { role : {{ users.data['0'].role === "user" ? "admin" : "user" }} } }
1 Like

Yay!!! That solved my problem, too! :partying_face: Thank you SOOOO much for posting your solution! :smiley:

Joel