I managed to setup Vapor with MongoDB and get it working but if I do a new clean project I get runtime error from MongoKitten. In detail:
I have an outdated vapor project that works fine from 27/07/2017. I do the same exactly project now 24/10/2017. When it compiles for the first time I get the following warning (don't know if is relevant to the following error):
Compilation finishes and I get the following error when I run the project:
I only know that this is caused by the preparation step in main.swift e.g. here:
config.preparations.append(User.self)
Without this step I dont get any runtime error (but fluent connection to mongodb isn't working properly either).
My config is pretty simple:
This happens in Swift 3.1.1 but same happens in Swift 4.0. Environment is Ubuntu 17.04.
How can I solve this?
MongoDB's $addFields stage requires MongoDB 3.4 or greater (we're almost at 3.6, so 3.4 is the latest release). I'm assuming you're running MongoDB 3.2 or lower. Ubuntu's official APT repository is and has been behind the official MongoDB releases for a long time. Some ubuntu versions will still install the deprecated 2.6 release of MongoDB.
The solution is to install the official latest MongoDB server as described here.