|
@@ -6,6 +6,7 @@ export interface IDBDocument<T extends {}> {
|
|
|
|
|
|
|
|
export interface IMongoService {
|
|
export interface IMongoService {
|
|
|
insertOne<T>(data: T): Promise<IDBDocument<T>>,
|
|
insertOne<T>(data: T): Promise<IDBDocument<T>>,
|
|
|
|
|
+ insertMany<T>(data: T[]): Promise<IDBDocument<T>[]|any[]>,
|
|
|
findOne<T>(query: FilterQuery<T>): Promise<IDBDocument<T>>,
|
|
findOne<T>(query: FilterQuery<T>): Promise<IDBDocument<T>>,
|
|
|
findOneById<T>(idParam: string): Promise<IDBDocument<T>>,
|
|
findOneById<T>(idParam: string): Promise<IDBDocument<T>>,
|
|
|
find<T>(query: FilterQuery<T>): Promise<IDBDocument<T>[]>,
|
|
find<T>(query: FilterQuery<T>): Promise<IDBDocument<T>[]>,
|
|
@@ -16,6 +17,7 @@ export const mongoService = (db: Db) => (col: string) => {
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
insertOne: <T>(data: T): Promise<IDBDocument<T>> => collection.insertOne(data).then(insertOneResult => insertOneResult.ops[0]),
|
|
insertOne: <T>(data: T): Promise<IDBDocument<T>> => collection.insertOne(data).then(insertOneResult => insertOneResult.ops[0]),
|
|
|
|
|
+ insertMany: <T>(data: T[]): Promise<any[]|IDBDocument<T>[]> => collection.insertMany(data).then(insertManyResult => insertManyResult.ops),
|
|
|
findOne: <T>(query: FilterQuery<T>) => collection.findOne(query),
|
|
findOne: <T>(query: FilterQuery<T>) => collection.findOne(query),
|
|
|
findOneById: (idParam: string) => collection.findOne({ _id: new ObjectId(idParam) }),
|
|
findOneById: (idParam: string) => collection.findOne({ _id: new ObjectId(idParam) }),
|
|
|
find: <T>(query: FilterQuery<T>): Promise<IDBDocument<T>[]> => collection.find(query).toArray(),
|
|
find: <T>(query: FilterQuery<T>): Promise<IDBDocument<T>[]> => collection.find(query).toArray(),
|