CoolFace
Apppublic

opusdev/vector-similarity-api

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes
common.ts277 linesDownload Raw Back to client_bulk_write
1import { type Document } from '../../bson';2import type { Filter, OptionalId, UpdateFilter, WithoutId } from '../../mongo_types';3import type { CollationOptions, CommandOperationOptions } from '../../operations/command';4import type { Hint } from '../../operations/operation';5import { type Sort } from '../../sort';6 7/** @public */8export interface ClientBulkWriteOptions extends CommandOperationOptions {9  /**10   * If true, when an insert fails, don't execute the remaining writes.11   * If false, continue with remaining inserts when one fails.12   * @defaultValue `true` - inserts are ordered by default13   */14  ordered?: boolean;15  /**16   * Allow driver to bypass schema validation.17   * @defaultValue `false` - documents will be validated by default18   **/19  bypassDocumentValidation?: boolean;20  /** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */21  let?: Document;22  /**23   * Whether detailed results for each successful operation should be included in the returned24   * BulkWriteResult.25   */26  verboseResults?: boolean;27}28 29/** @public */30export interface ClientWriteModel {31  /**32   * The namespace for the write.33   *34   * A namespace is a combination of the database name and the name of the collection: `<database-name>.<collection>`.35   * All documents belong to a namespace.36   *37   * @see https://www.mongodb.com/docs/manual/reference/limits/#std-label-faq-dev-namespace38   */39  namespace: string;40}41 42/** @public */43export interface ClientInsertOneModel<TSchema> extends ClientWriteModel {44  name: 'insertOne';45  /** The document to insert. */46  document: OptionalId<TSchema>;47}48 49/** @public */50export interface ClientDeleteOneModel<TSchema> extends ClientWriteModel {51  name: 'deleteOne';52  /**53   * The filter used to determine if a document should be deleted.54   * For a deleteOne operation, the first match is removed.55   */56  filter: Filter<TSchema>;57  /** Specifies a collation. */58  collation?: CollationOptions;59  /** The index to use. If specified, then the query system will only consider plans using the hinted index. */60  hint?: Hint;61}62 63/** @public */64export interface ClientDeleteManyModel<TSchema> extends ClientWriteModel {65  name: 'deleteMany';66  /**67   * The filter used to determine if a document should be deleted.68   * For a deleteMany operation, all matches are removed.69   */70  filter: Filter<TSchema>;71  /** Specifies a collation. */72  collation?: CollationOptions;73  /** The index to use. If specified, then the query system will only consider plans using the hinted index. */74  hint?: Hint;75}76 77/** @public */78export interface ClientReplaceOneModel<TSchema> extends ClientWriteModel {79  name: 'replaceOne';80  /**81   * The filter used to determine if a document should be replaced.82   * For a replaceOne operation, the first match is replaced.83   */84  filter: Filter<TSchema>;85  /** The document with which to replace the matched document. */86  replacement: WithoutId<TSchema>;87  /** Specifies a collation. */88  collation?: CollationOptions;89  /** The index to use. If specified, then the query system will only consider plans using the hinted index. */90  hint?: Hint;91  /** When true, creates a new document if no document matches the query. */92  upsert?: boolean;93  /** Specifies the sort order for the documents matched by the filter. */94  sort?: Sort;95}96 97/** @public */98export interface ClientUpdateOneModel<TSchema> extends ClientWriteModel {99  name: 'updateOne';100  /**101   * The filter used to determine if a document should be updated.102   * For an updateOne operation, the first match is updated.103   */104  filter: Filter<TSchema>;105  /**106   * The modifications to apply. The value can be either:107   * UpdateFilter<Document> - A document that contains update operator expressions,108   * Document[] - an aggregation pipeline.109   */110  update: UpdateFilter<TSchema> | Document[];111  /** A set of filters specifying to which array elements an update should apply. */112  arrayFilters?: Document[];113  /** Specifies a collation. */114  collation?: CollationOptions;115  /** The index to use. If specified, then the query system will only consider plans using the hinted index. */116  hint?: Hint;117  /** When true, creates a new document if no document matches the query. */118  upsert?: boolean;119  /** Specifies the sort order for the documents matched by the filter. */120  sort?: Sort;121}122 123/** @public */124export interface ClientUpdateManyModel<TSchema> extends ClientWriteModel {125  name: 'updateMany';126  /**127   * The filter used to determine if a document should be updated.128   * For an updateMany operation, all matches are updated.129   */130  filter: Filter<TSchema>;131  /**132   * The modifications to apply. The value can be either:133   * UpdateFilter<Document> - A document that contains update operator expressions,134   * Document[] - an aggregation pipeline.135   */136  update: UpdateFilter<TSchema> | Document[];137  /** A set of filters specifying to which array elements an update should apply. */138  arrayFilters?: Document[];139  /** Specifies a collation. */140  collation?: CollationOptions;141  /** The index to use. If specified, then the query system will only consider plans using the hinted index. */142  hint?: Hint;143  /** When true, creates a new document if no document matches the query. */144  upsert?: boolean;145}146 147/**148 * Used to represent any of the client bulk write models that can be passed as an array149 * to MongoClient#bulkWrite.150 * @public151 */152export type AnyClientBulkWriteModel<TSchema extends Document> =153  | ClientInsertOneModel<TSchema>154  | ClientReplaceOneModel<TSchema>155  | ClientUpdateOneModel<TSchema>156  | ClientUpdateManyModel<TSchema>157  | ClientDeleteOneModel<TSchema>158  | ClientDeleteManyModel<TSchema>;159 160/**161 * A mapping of namespace strings to collections schemas.162 * @public163 *164 * @example165 * ```ts166 * type MongoDBSchemas = {167 *   'db.books': Book;168 *   'db.authors': Author;169 * }170 *171 * const model: ClientBulkWriteModel<MongoDBSchemas> = {172 *   namespace: 'db.books'173 *   name: 'insertOne',174 *   document: { title: 'Practical MongoDB Aggregations', authorName: 3 } // error `authorName` cannot be number175 * };176 * ```177 *178 * The type of the `namespace` field narrows other parts of the BulkWriteModel to use the correct schema for type assertions.179 *180 */181export type ClientBulkWriteModel<182  SchemaMap extends Record<string, Document> = Record<string, Document>183> = {184  [Namespace in keyof SchemaMap]: AnyClientBulkWriteModel<SchemaMap[Namespace]> & {185    namespace: Namespace;186  };187}[keyof SchemaMap];188 189/** @public */190export interface ClientBulkWriteResult {191  /**192   * Whether the bulk write was acknowledged.193   */194  readonly acknowledged: boolean;195  /**196   * The total number of documents inserted across all insert operations.197   */198  readonly insertedCount: number;199  /**200   * The total number of documents upserted across all update operations.201   */202  readonly upsertedCount: number;203  /**204   * The total number of documents matched across all update operations.205   */206  readonly matchedCount: number;207  /**208   * The total number of documents modified across all update operations.209   */210  readonly modifiedCount: number;211  /**212   * The total number of documents deleted across all delete operations.213   */214  readonly deletedCount: number;215  /**216   * The results of each individual insert operation that was successfully performed.217   */218  readonly insertResults?: ReadonlyMap<number, ClientInsertOneResult>;219  /**220   * The results of each individual update operation that was successfully performed.221   */222  readonly updateResults?: ReadonlyMap<number, ClientUpdateResult>;223  /**224   * The results of each individual delete operation that was successfully performed.225   */226  readonly deleteResults?: ReadonlyMap<number, ClientDeleteResult>;227}228 229/** @public */230export interface ClientBulkWriteError {231  code: number;232  message: string;233}234 235/** @public */236export interface ClientInsertOneResult {237  /**238   * The _id of the inserted document.239   */240  insertedId: any;241}242 243/** @public */244export interface ClientUpdateResult {245  /**246   * The number of documents that matched the filter.247   */248  matchedCount: number;249 250  /**251   * The number of documents that were modified.252   */253  modifiedCount: number;254 255  /**256   * The _id field of the upserted document if an upsert occurred.257   *258   * It MUST be possible to discern between a BSON Null upserted ID value and this field being259   * unset. If necessary, drivers MAY add a didUpsert boolean field to differentiate between260   * these two cases.261   */262  upsertedId?: any;263 264  /**265   * Determines if the upsert did include an _id, which includes the case of the _id being null.266   */267  didUpsert: boolean;268}269 270/** @public */271export interface ClientDeleteResult {272  /**273   * The number of documents that were deleted.274   */275  deletedCount: number;276}277