私はmongodb、node.node.jsの初心者です。このプラットフォームはバックエンドに適していることを学んだ後、私はmongodbをデータベースとして実行したい小さなプロジェクトに取り組みました。どのように私mongodbとnode.jsを使ってfindItemを約束する
そして今、私は自分のモバイルアプリケーションのためのAPIに取り組んでいますが、私の挑戦は、私はそれを作成した後に、単一の項目を読み取る方法を知らないで、
は、任意のヘルプみんな
がここにありますですアイテムを作成しています
'use strict';
const express = require("express");
const router = express.Router();
const lesson = require('../models/lesson');
exports.getLessons = title =>
//CREATE lessons
export.createNewLesson = (image, title, grade, lessonObjective, subject, chapter, description, username:username)=>{
new Prmise((resolve, reject)=>{
const newLesson = new lesson({
image :image,
title :title,
grade :grade,
lessonObjective :lessonObjective,
subject :subject,
chapter :chapter,
description :description,
created_at : new Date(),
const author = {
id: req.user._id,
username: req.user.username
},
})
newLesson.save();
.then(()=> resolve({ status: 201, message: 'successfully added new lesson'}))
.catch(err =>{
if (err.code == 11000) {
reject({ status: 409, message: 'There is a similar lesson with the same !' });
} else {
reject({ status: 500, message: 'Internal Server Error !' });
}
});
});
// GET all lessons
new Promise((resolve,reject) => {
lesson.find({ title: title },
{ image: 1,
title: 1,
grade: 1,
subject : 1,
chapter: 1,
lessonObjective: 1,
description: 1,
created_at: 1,
_id: 0
})
.then(lessons => resolve(lessons[0]))
.catch(err => reject({ status: 500, message: 'Internal Server Error !' }))
});
// GET lesson by id
//UPDATE lesson
}
SOの質問をする前に、コードを適切にフォーマットし、構文エラーを修正してください( 'username:username'をパラメータとして定義するか、' new Prmise'を呼び出すなど)。 – nem035