mongoose#UpdateQuery TypeScript Examples
The following examples show how to use
mongoose#UpdateQuery.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: user.service.ts From NextJS-NestJS-GraphQL-Starter with MIT License | 6 votes |
async updateById({
userId,
input,
}: {
userId: User['_id'];
input: UpdateQuery<User>;
}): Promise<User> {
return this.userModel
.findByIdAndUpdate(userId, input, { new: true })
.exec();
}
Example #2
Source File: model-methods.ts From server with GNU General Public License v3.0 | 6 votes |
/**
* Edit Data in Database of the Particular Model after Verification
*
* @param {Model} model - Model in the Database
* @param {Object} data - Data Document from the Database
* @param {Object} modifiedData - Modified Data
* @param {IUserDoc} admin - Admin user Document from Database
* @param {Readonly<IPolicy>[]} policies - Array of Policies Applicable for the Function
* @returns {Promise<boolean>} - always resolves to true or throws error
*/
export async function editDatainDatabase<
U extends Document,
V extends Model<U>,
>(
model: V,
data: U,
modifiedData: UpdateQuery<U>,
admin: IUserDoc,
policies: Readonly<IPolicy>[],
): Promise<boolean> {
await checkPolicy(policies, admin);
await model.updateOne({ _id: data._id }, modifiedData);
return true;
}
Example #3
Source File: BaseMongoRepository.ts From node-experience with MIT License | 5 votes |
async update(entity: T): Promise<T>
{
return this.repository.findOneAndUpdate({ _id: entity.getId() } as FilterQuery<T>, { $set: entity } as UpdateQuery<T>, { new: true }).populate(this.populate as string | string[]) as any;
}
Example #4
Source File: Structure.ts From Asena with MIT License | 5 votes |
async update(query: UpdateQuery<D>, rePatch: boolean = true){
const update = await this.model.findByIdAndUpdate(this.id, query, {
new: rePatch
})
this.patch(update)
}