简体   繁体   中英

Vapor MongoDB Provider Error

I am trying to run a Vapor app on my local machine and have MongoDb installed and running.

I have this as my mongo.json: { "user": "test", "password": "password", "database": "reading_journal", "host": "127.0.0.1", "port": 2701 }

which is correct in terms of the info for the local DB.

My main.swift:

import Vapor
import FluentMongo
import VaporMongo


let drop = Droplet(providers: [VaporMongo.Provider.self])

drop.get { req in
    let lang = req.headers["Accept-Language"]?.string ?? "en"
    return try drop.view.make("welcome", [
        "message": Node.string(drop.localization[lang, "welcome", "title"])
    ])
}

drop.resource("users", UserController())
drop.resource("posts", PostController())

drop.run()

Yet in the log I get: "Could not initialize provider Provider: Socket failed with code 61 ("No data available") [connectFailed] "Unknown error"

Is there some other initialization that needs to be done? This is a brand new MongoDB DB.

Any help would be greatly appreciated!

就我而言,我必须在mongo.json添加"host": "0.0.0.0"

That error usually happens if MongoDB is not running on the correct port. Make sure whatever you have in your mongo.json file matches what port MongoDB is running on.

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