代码之家  ›  专栏  ›  技术社区  ›  user3069488

震波。D-未定义标识符(Dlang)

  •  0
  • user3069488  · 技术社区  · 8 年前

    我试图创建简单的RESTAPI,但当我试图编译代码时,我发现

    别名“cmp”?

    这是我的代码:

    module service.frontpage;
    
    import vibe.d;
    
    @path("/api")
    interface IFrontPageAPI
    {
      Json getHome();
    }
    
    class FrontPageAPI : IFrontPageAPI
    {
    
    
      this(auto tmp) 
      {
        auto collect = tmp;
      }
    
      Json getHome()
      {
        logInfo("Getting HomePage from DB");  
        Bson query = Bson(["_id" : Bson("homepage")]);
        auto result = collect.find(query);
    
    
        logInfo("Iterating results...");
        foreach (i, doc; result.byPair)
        logInfo("Item %d: %s", i, doc.toJson().toString());
    
        return result.toJson();
      }
    }
    

    有人能帮我吗?tmp是传递mongoDB集合处理程序的临时变量。

    1 回复  |  直到 8 年前
        1
  •  2
  •   greenify    8 年前

    与上的答案相同 DLearn .

    你需要 -使用类型而不是自动(此处为Mongo集合) -返回正确的Json

    this interactive example -尽情玩玩吧。没有输出意味着没有编译错误。

    推荐文章