[英]Node.js get mothod ? What does this "Blog.find().sort()means?
I was in node.js tutorial and teacher writed this code我在node.js教程和老师写了这段代码
app4.get('/',(req,res)=>{
Blog.find().sort({createdAt :1})
.then((result)=>{
res.render('index',{
title: 'Anasayfa', blogs:result})
})
.catch((err)=>{
console.log(err)
})
})
I didnt understand that what does "Blog" does and means in there, is it a object from a module or something else?我不明白“博客”在其中的作用和含义是什么,它是来自模块的 object 还是其他什么? I asked teacher but he didn't response to me.
我问老师,但他没有回应我。 When I execute that code I receive error "Blog is not defined" that means first I gotto define Blog but how to define?
当我执行该代码时,我收到错误“博客未定义”,这意味着我首先要定义博客,但如何定义? By bulding a module or file?
通过构建模块或文件?
I appreciate every response, thankk you for your time感谢您的每一个回复,感谢您的宝贵时间
Unfortunately, with the code shown, we don't know what it means either.不幸的是,对于显示的代码,我们也不知道它的含义。 :-)
:-)
Whomever wrote the code will have to explain.谁写的代码都得解释。 However, we can say that this type of pattern is typical for a database backend.
但是,我们可以说这种模式对于数据库后端来说是典型的。
Blog
is probably a database model . Blog
可能是一个数据库 model 。 Think of it like a class or type of object.可以将其想象为class或 object 类型。 By calling
Blog.find()
, you're likely fetching all the blogs (or blog articles, whatever it is).通过调用
Blog.find()
,您可能会获取所有博客(或博客文章,无论它是什么)。 Then calling .sort()
on that result set, you're sorting by the createdAt
attribute.然后在该结果集上调用
.sort()
,您createdAt
属性进行排序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.