简体   繁体   中英

Vibe.D - undefinded identifier (Dlang)

I'm trying to create simple REST api, but when i try to compile my code im getting

frontpage.d(15,3): Error: undefined identifier 'tmp', did you mean alias 'cmp'?

Here is my code:

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();
  }
}

Can someone help me with it? tmp is temporary variable to pass mongoDB collection handler.

Same answer as on DLearn .

You need to - use Class variables - use types instead auto (here Mongo collection) - return a proper Json

Have a look at this interactive example - and feel free to play with it. No output means no compilation error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM