;
-
void this.pendingIndexes.finally(() => {
this.pendingIndexes = undefined;
});
-
return this.pendingIndexes;
}
}
@@ -148,22 +128,17 @@ export abstract class BaseRaw<
}
private ensureDefaultFields(options: FindOptions
): FindOptions
;
-
private ensureDefaultFields
(
options?: FindOptions
& { fields?: FindOptions
['projection'] },
): FindOptions
| FindOptions | undefined {
if (options?.fields) {
warnFields("Using 'fields' in models is deprecated.", options);
}
-
if (this.defaultFields === undefined) {
return options;
}
-
const { fields: deprecatedFields, projection, ...rest } = options || {};
-
const fields = { ...deprecatedFields, ...projection };
-
return {
projection: this.defaultFields,
...(fields && Object.values(fields).length && { projection: fields }),
@@ -173,167 +148,26 @@ export abstract class BaseRaw<
public findOneAndUpdate(query: Filter, update: UpdateFilter | T, options?: FindOneAndUpdateOptions): Promise | null> {
this.setUpdatedAt(update);
-
if (options?.upsert && !('_id' in update || (update.$set && '_id' in update.$set)) && !('_id' in query)) {
- update.$setOnInsert = {
- ...(update.$setOnInsert || {}),
- _id: new ObjectId().toHexString(),
- } as Partial & { _id: string };
+ update.$setOnInsert = { ...(update.$setOnInsert || {}), _id: new ObjectId().toHexString() } as Partial & { _id: string };
}
-
return this.col.findOneAndUpdate(query, update, options || {});
}
async findOneById(_id: T['_id'], options?: FindOptions): Promise;
-
async findOneById(_id: T['_id'], options?: FindOptions
): Promise
;
-
async findOneById(_id: T['_id'], options?: any): Promise {
const query: Filter = { _id } as Filter;
- if (options) {
- return this.findOne(query, options);
- }
- return this.findOne(query);
+ return options ? this.findOne(query, options) : this.findOne(query);
}
- async findOne(query?: Filter | T['_id'], options?: undefined): Promise;
-
- async findOne(query: Filter | T['_id'], options?: FindOptions): Promise
;
-
- async findOne
(query: Filter | T['_id'] = {}, options?: any): Promise | WithId | null> {
+ async findOne
(query: Filter | T['_id'] = {}, options?: any): Promise | WithId | null> {
const q: Filter = typeof query === 'string' ? ({ _id: query } as Filter) : query;
const optionsDef = this.doNotMixInclusionAndExclusionFields(options);
- if (optionsDef) {
- return this.col.findOne(q, optionsDef);
- }
- return this.col.findOne(q);
- }
-
- find(query?: Filter): FindCursor>;
-
- find(query: Filter, options?: FindOptions): FindCursor
;
-
- find
(
- query: Filter = {},
- options?: FindOptions,
- ): FindCursor> | FindCursor