How to use the @reactioncommerce/api-utils/collectionIndex.js function in @reactioncommerce/api-utils

To help you get started, we’ve selected a few @reactioncommerce/api-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github reactioncommerce / reaction / src / core / ReactionAPI.js View on Github external
throw new Error(`In registerPlugin, collection "${collectionKey}" needs a name property`);
              }

              // Validate that the `collections` key hasn't already been taken by another plugin
              if (this.collections[collectionKey]) {
                throw new Error(`Plugin ${pluginName} defines a collection with key "${collectionKey}" in registerPlugin,` +
                  " but another plugin has already defined a collection with that key");
              }

              // Add the collection instance to `context.collections`
              this.collections[collectionKey] = this.db.collection(collectionConfig.name);

              // If the collection config has `indexes` key, define all requested indexes
              if (Array.isArray(collectionConfig.indexes)) {
                for (const indexArgs of collectionConfig.indexes) {
                  collectionIndex(this.collections[collectionKey], ...indexArgs);
                }
              }
            }
          }
        }
      }
    }
  }