MongoDB如何通过帖子吸引用户

时间:2020-06-06 20:17:24

标签: javascript node.js mongodb mongoose web-deployment

获取帖子的用户时遇到问题

用户架构及其所有相关的信息。

const answersSchema = new mongoose.Schema({
  description: String,
  code: String,
  postDate: String
});

const questionsSchema=new mongoose.Schema({
  title: String,
  description: String,
  code: String,
  postDate: String,
  answers: [answersSchema]

});

const blogpostsSchema=new mongoose.Schema({
  title:String,
  content:String,
  postDate: String

});
const clientSchema= new mongoose.Schema({
  email: String,
  password: String,
  googleId: String,
  thumbnail: String,
  blogPosts: [blogpostsSchema],
  questions: [questionsSchema]
});

const Client = mongoose.model("Client",clientSchema);
const BlogPost= mongoose.model("BlogPost",blogpostsSchema);
const Answer = mongoose.model("Answer", answersSchema);
const Question =mongoose.model("Question",questionsSchema);

这是我的查询

Client.find({"blogPosts": {$exists: true}},function(err,foundUser){
    if (foundUser){
      console.log(foundUser)
      res.render("blog",{userWithPosts: foundUser,  clientStatus: clientStatus, logButton: logButton})
    } else {
      if(err){
        console.log(err);
      }
    }


})

通过此查询,出现了问题。

我想要拥有博客帖子的客户

如何检查CLIENT是否在blogPosts中有帖子

0 个答案:

没有答案