mongodb-crud

This commit is contained in:
King Wang 2021-06-27 01:56:15 +08:00
parent 4a74c31258
commit a0d1437b2d
2 changed files with 7 additions and 13 deletions

View File

@ -3,14 +3,6 @@ import { Global } from "../models/Global";
import { ReqAddPost, ResAddPost } from "../shared/protocols/PtlAddPost"; import { ReqAddPost, ResAddPost } from "../shared/protocols/PtlAddPost";
export async function ApiAddPost(call: ApiCall<ReqAddPost, ResAddPost>) { export async function ApiAddPost(call: ApiCall<ReqAddPost, ResAddPost>) {
console.log('cccgasdgasd', call.service.conf)
if (call.service.conf) {
// if (没登录) {
// call.error('你还没登录');
// return;
// }
}
let op = await Global.collection('Post').insertOne({ let op = await Global.collection('Post').insertOne({
...call.req.newPost, ...call.req.newPost,
create: { create: {

View File

@ -9,13 +9,15 @@ export async function ApiUpdatePost(call: ApiCall<ReqUpdatePost, ResUpdatePost>)
let op = await Global.collection('Post').updateOne({ let op = await Global.collection('Post').updateOne({
_id: new ObjectID(_id) _id: new ObjectID(_id)
}, { }, {
$set: update $set: {
...update,
update: {
uid: 'xxx',
time: new Date()
}
}
}); });
console.log('ssss', {
matchedCount: op.matchedCount
})
call.succ({ call.succ({
matchedCount: op.matchedCount matchedCount: op.matchedCount
}) })