This commit is contained in:
2020-01-07 10:00:32 +08:00
parent e078e7d503
commit f13e98568b
11 changed files with 65 additions and 59 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@cc-server/db-mongo",
"version": "0.6.9",
"version": "0.7.0",
"description": "> TODO: description",
"author": "MiaoWoo <admin@yumc.pw>",
"homepage": "https://faas.yumc.pw",
@@ -20,17 +20,17 @@
"url": "git+https://github.com/502647092/cc-server-parent.git"
},
"dependencies": {
"@cc-server/db": "^0.6.9",
"@cc-server/ioc": "^0.6.9",
"@cc-server/db": "^0.7.0",
"@cc-server/ioc": "^0.7.0",
"inversify": "^5.0.1",
"mongodb": "^3.2.7",
"mongodb": "^3.4.1",
"reflect-metadata": "^0.1.13"
},
"devDependencies": {
"@types/mongodb": "^3.1.28",
"mocha": "^6.1.4",
"rimraf": "^2.6.3",
"typescript": "^3.5.1"
"@types/mongodb": "^3.3.14",
"mocha": "^7.0.0",
"rimraf": "^3.0.0",
"typescript": "^3.7.4"
},
"gitHead": "7d84393a3cb6be6be9ed51d71f12677d2d7d0728"
}

View File

@@ -16,7 +16,7 @@ export class MongoCollection<T = any> implements DBClient {
return await this.collection.find(filter).toArray();
}
public async findOne(filter: Object): Promise<T> {
public async findOne(filter: object): Promise<T> {
let result = await this.collection.find(filter).limit(1).toArray();
return result[0];
}
@@ -26,20 +26,21 @@ export class MongoCollection<T = any> implements DBClient {
}
public async insertOne(model: T): Promise<T> {
//@ts-ignore
var insert = await this.collection.insertOne(model);
return insert.ops[0];
}
public async updateOne(where: any, model: any): Promise<boolean> {
public async updateOne(where: any, model: T): Promise<boolean> {
let result = await this.collection.updateOne(where, { $set: model });
return result.result.ok == 1 && result.result.n > 0;
}
public async updateById(objectId: string, model: any): Promise<boolean> {
public async updateById(objectId: string, model: T): Promise<boolean> {
return await this.updateOne({ _id: new ObjectID(objectId) }, model)
}
public async deleteOne(where: any): Promise<boolean> {
public async deleteOne(where: object): Promise<boolean> {
let result = await this.collection.deleteOne(where);
return result.result.ok === 1 && result.result.n > 0
}