Skip to content

Commit

Permalink
Merge branch 'master' into 8.8
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Oct 15, 2024
2 parents 84fe02c + 0752c5d commit 3068872
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -3807,7 +3807,7 @@ Model.hydrate = function(obj, projection, options) {
* const res = await Person.updateMany({ name: /Stark$/ }, { isDeleted: true });
* res.matchedCount; // Number of documents matched
* res.modifiedCount; // Number of documents modified
* res.acknowledged; // Boolean indicating everything went smoothly.
* res.acknowledged; // Boolean indicating the MongoDB server received the operation. This may be false if Mongoose did not send an update to the server because the update was empty.
* res.upsertedId; // null or an id containing a document that had to be upserted.
* res.upsertedCount; // Number indicating how many documents had to be upserted. Will either be 0 or 1.
*
Expand Down Expand Up @@ -3847,7 +3847,7 @@ Model.updateMany = function updateMany(conditions, doc, options) {
* const res = await Person.updateOne({ name: 'Jean-Luc Picard' }, { ship: 'USS Enterprise' });
* res.matchedCount; // Number of documents matched
* res.modifiedCount; // Number of documents modified
* res.acknowledged; // Boolean indicating everything went smoothly.
* res.acknowledged; // Boolean indicating the MongoDB server received the operation. This may be false if Mongoose did not send an update to the server because the update was empty.
* res.upsertedId; // null or an id containing a document that had to be upserted.
* res.upsertedCount; // Number indicating how many documents had to be upserted. Will either be 0 or 1.
*
Expand Down Expand Up @@ -3885,7 +3885,7 @@ Model.updateOne = function updateOne(conditions, doc, options) {
* const res = await Person.replaceOne({ _id: 24601 }, { name: 'Jean Valjean' });
* res.matchedCount; // Number of documents matched
* res.modifiedCount; // Number of documents modified
* res.acknowledged; // Boolean indicating everything went smoothly.
* res.acknowledged; // Boolean indicating the MongoDB server received the operation.
* res.upsertedId; // null or an id containing a document that had to be upserted.
* res.upsertedCount; // Number indicating how many documents had to be upserted. Will either be 0 or 1.
*
Expand Down
6 changes: 3 additions & 3 deletions test/types/models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import mongoose, {
UpdateWriteOpResult,
AggregateOptions,
WithLevel1NestedPaths,
NestedPaths,
InferSchemaType
InferSchemaType,
DeleteResult
} from 'mongoose';
import { expectAssignable, expectError, expectType } from 'tsd';
import { AutoTypedSchemaType, autoTypedSchema } from './schema.test';
Expand Down Expand Up @@ -514,7 +514,7 @@ function gh12100() {
function modelRemoveOptions() {
const cmodel = model('Test', new Schema());

cmodel.deleteOne({}, {});
const res: DeleteResult = await cmodel.deleteOne({}, {});
}

async function gh12286() {
Expand Down
18 changes: 18 additions & 0 deletions test/types/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1645,3 +1645,21 @@ function gh8389() {
function gh14879() {
Schema.Types.String.setters.push((val?: unknown) => typeof val === 'string' ? val.trim() : val);
}

async function gh14950() {
const SightingSchema = new Schema(
{
_id: { type: Schema.Types.ObjectId, required: true },
location: {
type: { type: String, required: true },
coordinates: [{ type: Number }]
}
}
);

const TestModel = model('Test', SightingSchema);
const doc = await TestModel.findOne().orFail();

expectType<string>(doc.location!.type);
expectType<number[]>(doc.location!.coordinates);
}
12 changes: 10 additions & 2 deletions types/inferschematype.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,16 @@ type TypeHint<T> = T extends { __typehint: infer U } ? U: never;
* @param {TypeKey} TypeKey A generic refers to document definition.
*/
type ObtainDocumentPathType<PathValueType, TypeKey extends string = DefaultTypeKey> = ResolvePathType<
PathValueType extends PathWithTypePropertyBaseType<TypeKey> ? PathValueType[TypeKey] : PathValueType,
PathValueType extends PathWithTypePropertyBaseType<TypeKey> ? Omit<PathValueType, TypeKey> : {},
PathValueType extends PathWithTypePropertyBaseType<TypeKey>
? PathValueType[TypeKey] extends PathWithTypePropertyBaseType<TypeKey>
? PathValueType
: PathValueType[TypeKey]
: PathValueType,
PathValueType extends PathWithTypePropertyBaseType<TypeKey>
? PathValueType[TypeKey] extends PathWithTypePropertyBaseType<TypeKey>
? {}
: Omit<PathValueType, TypeKey>
: {},
TypeKey,
TypeHint<PathValueType>
>;
Expand Down
2 changes: 2 additions & 0 deletions types/models.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ declare module 'mongoose' {
};

type UpdateWriteOpResult = mongodb.UpdateResult;
type UpdateResult = mongodb.UpdateResult;
type DeleteResult = mongodb.DeleteResult;

interface MapReduceOptions<T, K, R> {
map: Function | string;
Expand Down

0 comments on commit 3068872

Please sign in to comment.