jeroen / mongolite

Fast and Simple MongoDB Client for R
https://jeroen.github.io/mongolite/
284 stars 64 forks source link

Disabling the BSON_VALIDATE_DOT_KEYS flag not possible #206

Open jrausch12 opened 4 years ago

jrausch12 commented 4 years ago

Hello!

First off, thank you for all the work you've done, allowing so many of us to easily interface with mongo collections.

I have documents converted to JSON from my R environment that have dots in the key names. I want to tell mongolite to set BSON_VALIDATE_DOT_KEYS to false, but I can't find a way to pass this in as an argument on the conn$insert method. Any help is greatly appreciated.

Even better would be a way to tell the method to just set check_keys:false

jeroen commented 4 years ago

It probably makes sense to disable this globally. Can you send a PR?

jrausch12 commented 4 years ago

@jeroen I actually found this at an earlier index in the repo here: https://github.com/jeroen/mongolite/blob/e5a628aea68543416bbbcf546f36ea61f5460a18/src/bson/bson.c#L3352

I can't seem to find this currently anywhere in the master branch. Think you could advise on how to best approach this?

jrausch12 commented 4 years ago

@jeroen any assistance would be helpful

jeroen commented 4 years ago

Reprex:

library(mongolite)
m <- mongo()
m$insert('{"foo.bar":123}')
## Warning: [WARNING] invalid document for insert: keys cannot contain ".": "foo.bar"
## Error: invalid document for insert: keys cannot contain ".": "foo.bar"
jeroen commented 4 years ago

@kevinalbs does the c driver have an api to change the _mongoc_default_insert_vflags? Or some other way to make bson_new_from_json accept BSON_VALIDATE_DOT_KEYS ?

kevinAlbs commented 4 years ago

Hi @jeroen! I am not aware of a way to override the defaults globally. The individual insert/update/delete helpers that accept a bson_t option argument containing "validate" with to override the validation flags. E.g. mongoc_collection_insert_one

Would passing custom validation flags on each operation be viable?

jeroen commented 4 years ago

@kevinAlbs hmm i'm not sure. The bindings also use these apis:

Perhaps others. Those do not seem to have a validate parameter?

kevinAlbs commented 4 years ago

Unfortunately, I do not believe there is a way to disable the validation at a broader scope than per-operation in the C driver. Disabling validation of dot/dollar is an issue that is common to multiple drivers, and the drivers team is planning to address this. In the meantime, I created https://jira.mongodb.org/browse/CDRIVER-3731 to allow configuring validation at a broader scope in the C driver.

For the time being, mongolite could replace those with calls to the variants that accept options mongoc_bulk_operation_insert_with_opts and mongoc_collection_insert_one. mongoc_bulk_operation_insert and mongoc_collection_insert are documented as being superseded by those regardless.