Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run a $convert update query with $update or $run command ? #235

Open
Wesseldr opened this issue Feb 3, 2022 · 0 comments
Open

How to run a $convert update query with $update or $run command ? #235

Wesseldr opened this issue Feb 3, 2022 · 0 comments

Comments

@Wesseldr
Copy link

Wesseldr commented Feb 3, 2022

Hi,

I'm trying to execute this query:

 db.rawclients.update(
    { _clientContract: { $type: 2 } },
    [{ $set: { _clientContract: { $convert: { input: "$_clientContract", to: 7 } } } }],
    { multi: true }
);
  • Running this query inside mongosh it just works fine.
  • rawclients$updates etc just works fine in mongolite but again using the query above complains about wrong JSON
  • Ultimate i thought of throwing this query into the $run command, that should work... but also here, complains about JSON
    Putting every field name and value inside "" still the JSON problem persists...

I'm pretty stuck... why something simple like:

query <- 'db.rawclients.update( 
          { _clientContract : { $type: 2 } }, 
          [{ $set: { _clientContract: { $convert: { input: "$_clientContract", to: 7 } } } }], 
          { multi: true } )'

Using build in $update:

rawclients$update(
    '{ _clientContract : { $type: 2 } }',
   '[{ $set: { _clientContract: { $convert: { input: "$_clientContract", to: 7 } } } }]',
   multiple = TRUE
)

Using run:

rawclients$run(query)

Is not working, what am I'm missing here ... al also tried the json command notation like

$run(command = "{\"ping\": 1}", simplify = TRUE) # that works.... instead adding the whole query inside like
$run(command = glue("{\"{query}\"): 1}", simplify = TRUE) # just blows up with a JSON error.

Putting " around every key/value also still fails.

Hope someone has a hint how to run this $type update query...
I'm inserting a large table in tibble format into mongodb that works great :), and after the insert I'm "restoring" the ObjectId's with this query :) During the insert it creates string fields for the foreigner keys I'm using in my document.. no problem expected behaviour but however hope to clean it up afterwards like this :)

JWR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant