jeroen / mongolite

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

Create unique index #164

Open gladkia opened 5 years ago

gladkia commented 5 years ago

Hi, I've just added the support for creating indices with "unique" property (.c/.R code + R unit tests).

In theory, the 'addOpts' parameter (the list) can be extended with other properties of the created index.

codecov-io commented 5 years ago

Codecov Report

Merging #164 into master will decrease coverage by 0.13%. The diff coverage is 3.84%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #164      +/-   ##
==========================================
- Coverage   37.65%   37.52%   -0.14%     
==========================================
  Files         130      130              
  Lines       21910    21929      +19     
==========================================
- Hits         8250     8228      -22     
- Misses      13660    13701      +41
Impacted Files Coverage Δ
src/collection.c 35.84% <0%> (-2.82%) :arrow_down:
R/client.R 32.14% <0%> (-4.6%) :arrow_down:
R/mongo.R 49.7% <50%> (ø) :arrow_up:
src/mongoc/mongoc-topology-description.c 54.73% <0%> (-2.52%) :arrow_down:
src/mongoc/mongoc-server-description.c 53.36% <0%> (-1.08%) :arrow_down:
src/gridfs.c 66.16% <0%> (-0.67%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update db768cb...c3df7ab. Read the comment docs.

jeroen commented 5 years ago

Thanks, will review this when I'm back from vacation.

jeroen commented 5 years ago

It would be nice if we can make this work for any option by passing down the options as a json object (as we do for the keys parameter).

gladkia commented 5 years ago

Hi @jeroen,

  1. I looked into the mongoDB options available for create_indexes() command.

We can split options into two categories:

  1. Do you mean changing 'addOpts' parameter from the list() to the JSON object? Sure, I can refactor code that way. This will be easy (asserts in R function) for the first category of options (single value elements) and will require more sophisticated actions (especially tests) for the second category (documents). We should probably define single argument per each option in the C function "R_mongo_collection_create_index" (to minimize the work on the C level as much as possible). Is that OK ?

  2. I think that we can start with single-value elements. This part of work is the easy to implement and test. Then we can consider adding document options. What do you think about it ?

ghost commented 3 years ago

Hi, is there any update on this? I can't see the addOpts parameter in run() yet.