@feathersjs/mongodb
Version:
Feathers MongoDB service adapter
61 lines (60 loc) • 3.44 kB
TypeScript
import { ObjectId, Collection, FindOptions, BulkWriteOptions, InsertOneOptions, DeleteOptions, CountDocumentsOptions, ReplaceOptions, FindOneAndReplaceOptions, Document, FindOneAndDeleteOptions } from 'mongodb';
import { AdapterBase, AdapterParams, AdapterServiceOptions, PaginationOptions, AdapterQuery } from '@feathersjs/adapter-commons';
import { Id, Paginated } from '@feathersjs/feathers';
export interface MongoDBAdapterOptions extends AdapterServiceOptions {
Model: Collection | Promise<Collection>;
disableObjectify?: boolean;
useEstimatedDocumentCount?: boolean;
}
export interface MongoDBAdapterParams<Q = AdapterQuery> extends AdapterParams<Q, Partial<MongoDBAdapterOptions>> {
pipeline?: Document[];
mongodb?: BulkWriteOptions | FindOptions | InsertOneOptions | DeleteOptions | CountDocumentsOptions | ReplaceOptions | FindOneAndReplaceOptions | FindOneAndDeleteOptions;
}
export type AdapterId = Id | ObjectId;
export type NullableAdapterId = AdapterId | null;
export declare class MongoDbAdapter<Result, Data = Partial<Result>, ServiceParams extends MongoDBAdapterParams<any> = MongoDBAdapterParams, PatchData = Partial<Data>> extends AdapterBase<Result, Data, PatchData, ServiceParams, MongoDBAdapterOptions, AdapterId> {
constructor(options: MongoDBAdapterOptions);
getObjectId(id: AdapterId): AdapterId;
filterQuery(id: NullableAdapterId, params: ServiceParams): {
filters: {
$select: string[];
$sort: {
[key: string]: 1 | -1;
};
$limit: number;
$skip: number;
};
query: {
[key: string]: any;
};
};
getModel(params?: ServiceParams): Promise<Collection<Document>>;
findRaw(params: ServiceParams): Promise<import("mongodb").FindCursor<import("mongodb").WithId<Document>>>;
aggregateRaw(params: ServiceParams): Promise<import("mongodb").AggregationCursor<Document>>;
makeFeathersPipeline(params: ServiceParams): Document[];
getProjection(select?: string[] | {
[key: string]: number;
}): {
[key: string]: number;
};
normalizeId<D>(id: NullableAdapterId, data: D): D;
countDocuments(params: ServiceParams): Promise<any>;
_get(id: AdapterId, params?: ServiceParams): Promise<Result>;
_find(params?: ServiceParams & {
paginate?: PaginationOptions;
}): Promise<Paginated<Result>>;
_find(params?: ServiceParams & {
paginate: false;
}): Promise<Result[]>;
_find(params?: ServiceParams): Promise<Paginated<Result> | Result[]>;
_create(data: Data, params?: ServiceParams): Promise<Result>;
_create(data: Data[], params?: ServiceParams): Promise<Result[]>;
_create(data: Data | Data[], _params?: ServiceParams): Promise<Result | Result[]>;
_patch(id: null, data: PatchData | Partial<Result>, params?: ServiceParams): Promise<Result[]>;
_patch(id: AdapterId, data: PatchData | Partial<Result>, params?: ServiceParams): Promise<Result>;
_patch(id: NullableAdapterId, data: PatchData | Partial<Result>, _params?: ServiceParams): Promise<Result | Result[]>;
_update(id: AdapterId, data: Data, params?: ServiceParams): Promise<Result>;
_remove(id: null, params?: ServiceParams): Promise<Result[]>;
_remove(id: AdapterId, params?: ServiceParams): Promise<Result>;
_remove(id: NullableAdapterId, _params?: ServiceParams): Promise<Result | Result[]>;
}