user3069488
user3069488

Reputation: 85

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.

Upvotes: 0

Views: 142

Answers (1)

greenify
greenify

Reputation: 1127

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.

Upvotes: 2

Related Questions