Coder Social home page Coder Social logo

mongodb-vapor-template's Introduction

mongodb-vapor-template

This repository contains a template which can be used for generating new projects using MongoDB and Vapor via MongoDBVapor with Vapor's command line tool, Vapor Toolbox:

vapor new MyProject --template https://github.com/mongodb/mongodb-vapor-template/

Getting Started

  1. Install Vapor Toolbox. Installation instructions can be found here for macOS and here for Linux.

  2. Initialize a new project from the command line, and move into the project directory:

vapor new MyProject --template https://github.com/mongodb/mongodb-vapor-template/
cd MyProject
  1. If you're using Linux The driver vendors and wraps the MongoDB C driver (libmongoc), which depends on a number of external C libraries when built in Linux environments. As a result, these libraries must be installed on your system in order to build the driver. To install those libraries, please follow the instructions from libmongoc's documentation.

  2. Set up a MongoDB deployment to connect to. You can install MongoDB, and (in a new terminal window) start up a standalone server locally (this will run on the default host/port, localhost:27017):

mongod --dbpath /data/path/here

Alternatively, you can use MongoDB Atlas to set up a fully managed MongoDB deployment in the cloud.

  1. If using Atlas, or a local host/port besides the default localhost:27017, set your MongoDB connection string via environment variable:
export MONGODB_URI='connection-string-here'
  1. Load some sample data into the database via the MongoDB shell:
mongo $MONGODB_URI home --eval "db.kittens.insert([{name:\"roscoe\",color:\"orange\", createdAt: new Date()},{name:\"chester\",color:\"tan\", createdAt: new Date()}])"

If using Atlas, you could also do this via Atlas Data Explorer.

  1. Build and run the application (this might take a while on the first time):
swift build
swift run
  1. If using Leaf, go to http://localhost:8080 to see your app in action and load a list of kittens! Else, you can run curl http://localhost:8080 to see the resulting JSON.

  2. To add a new kitten: if using Leaf, use the form at http://localhost:8080. Else, you can add new data via curl: curl -d "name=Bob&color=white" http://localhost:8080.

Resources:

Get in Touch

Notice any issues with this template, or have ideas for how to make it more useful? Feel free to open a pull request or GitHub issue, or reach out to us on the SWIFT Jira project.

mongodb-vapor-template's People

Contributors

bajanam avatar kmahar avatar sarah-valdez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

isabella232

mongodb-vapor-template's Issues

Running the app test fails with error `Assertion failed: MongoClient was not closed before deinitialization. Please call `close()` or `syncClose()` when the client is no longer needed`

Versions/Environment

  1. What version of Swift are you using? (Run swift --version)
    swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100) Target: arm64-apple-macosx13.0
  2. What operating system are you using? (Run uname -a)
    Darwin thomass-macbook-pro.home 22.4.0 Darwin Kernel Version 22.4.0: Mon Mar 6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000 arm64
  3. What versions of the driver and its dependencies are you using? (Run swift package show-dependencies)
.
├── vapor<https://github.com/vapor/[email protected]>
│   ├── async-http-client<https://github.com/swift-server/[email protected]>
│   │   ├── swift-nio<https://github.com/apple/[email protected]>
│   │   │   ├── swift-atomics<https://github.com/apple/[email protected]>
│   │   │   └── swift-collections<https://github.com/apple/[email protected]>
│   │   ├── swift-nio-ssl<https://github.com/apple/[email protected]>
│   │   │   └── swift-nio<https://github.com/apple/[email protected]>
│   │   │       ├── swift-atomics<https://github.com/apple/[email protected]>
│   │   │       └── swift-collections<https://github.com/apple/[email protected]>
│   │   ├── swift-nio-http2<https://github.com/apple/[email protected]>
│   │   │   ├── swift-nio<https://github.com/apple/[email protected]>
│   │   │   │   ├── swift-atomics<https://github.com/apple/[email protected]>
│   │   │   │   └── swift-collections<https://github.com/apple/[email protected]>
│   │   │   └── swift-atomics<https://github.com/apple/[email protected]>
│   │   ├── swift-nio-extras<https://github.com/apple/[email protected]>
│   │   │   └── swift-nio<https://github.com/apple/[email protected]>
│   │   │       ├── swift-atomics<https://github.com/apple/[email protected]>
│   │   │       └── swift-collections<https://github.com/apple/[email protected]>
│   │   ├── swift-nio-transport-services<https://github.com/apple/[email protected]>
│   │   │   ├── swift-nio<https://github.com/apple/[email protected]>
│   │   │   │   ├── swift-atomics<https://github.com/apple/[email protected]>
│   │   │   │   └── swift-collections<https://github.com/apple/[email protected]>
│   │   │   └── swift-atomics<https://github.com/apple/[email protected]>
│   │   ├── swift-log<https://github.com/apple/[email protected]>
│   │   └── swift-atomics<https://github.com/apple/[email protected]>
│   ├── async-kit<https://github.com/vapor/[email protected]>
│   │   ├── swift-nio<https://github.com/apple/[email protected]>
│   │   │   ├── swift-atomics<https://github.com/apple/[email protected]>
│   │   │   └── swift-collections<https://github.com/apple/[email protected]>
│   │   └── swift-log<https://github.com/apple/[email protected]>
│   ├── console-kit<https://github.com/vapor/[email protected]>
│   │   └── swift-log<https://github.com/apple/[email protected]>
│   ├── swift-crypto<https://github.com/apple/[email protected]>
│   ├── routing-kit<https://github.com/vapor/[email protected]>
│   │   └── swift-log<https://github.com/apple/[email protected]>
│   ├── swift-backtrace<https://github.com/swift-server/[email protected]>
│   ├── swift-nio<https://github.com/apple/[email protected]>
│   │   ├── swift-atomics<https://github.com/apple/[email protected]>
│   │   └── swift-collections<https://github.com/apple/[email protected]>
│   ├── swift-nio-ssl<https://github.com/apple/[email protected]>
│   │   └── swift-nio<https://github.com/apple/[email protected]>
│   │       ├── swift-atomics<https://github.com/apple/[email protected]>
│   │       └── swift-collections<https://github.com/apple/[email protected]>
│   ├── swift-nio-http2<https://github.com/apple/[email protected]>
│   │   ├── swift-nio<https://github.com/apple/[email protected]>
│   │   │   ├── swift-atomics<https://github.com/apple/[email protected]>
│   │   │   └── swift-collections<https://github.com/apple/[email protected]>
│   │   └── swift-atomics<https://github.com/apple/[email protected]>
│   ├── swift-nio-extras<https://github.com/apple/[email protected]>
│   │   └── swift-nio<https://github.com/apple/[email protected]>
│   │       ├── swift-atomics<https://github.com/apple/[email protected]>
│   │       └── swift-collections<https://github.com/apple/[email protected]>
│   ├── swift-log<https://github.com/apple/[email protected]>
│   ├── swift-metrics<https://github.com/apple/[email protected]>
│   ├── swift-algorithms<https://github.com/apple/[email protected]>
│   │   └── swift-numerics<https://github.com/apple/[email protected]>
│   ├── websocket-kit<https://github.com/vapor/[email protected]>
│   │   ├── swift-nio<https://github.com/apple/[email protected]>
│   │   │   ├── swift-atomics<https://github.com/apple/[email protected]>
│   │   │   └── swift-collections<https://github.com/apple/[email protected]>
│   │   ├── swift-nio-ssl<https://github.com/apple/[email protected]>
│   │   │   └── swift-nio<https://github.com/apple/[email protected]>
│   │   │       ├── swift-atomics<https://github.com/apple/[email protected]>
│   │   │       └── swift-collections<https://github.com/apple/[email protected]>
│   │   ├── swift-nio-transport-services<https://github.com/apple/[email protected]>
│   │   │   ├── swift-nio<https://github.com/apple/[email protected]>
│   │   │   │   ├── swift-atomics<https://github.com/apple/[email protected]>
│   │   │   │   └── swift-collections<https://github.com/apple/[email protected]>
│   │   │   └── swift-atomics<https://github.com/apple/[email protected]>
│   │   └── swift-atomics<https://github.com/apple/[email protected]>
│   └── multipart-kit<https://github.com/vapor/[email protected]>
│       ├── swift-nio<https://github.com/apple/[email protected]>
│       │   ├── swift-atomics<https://github.com/apple/[email protected]>
│       │   └── swift-collections<https://github.com/apple/[email protected]>
│       └── swift-collections<https://github.com/apple/[email protected]>
└── mongodb-vapor<https://github.com/mongodb/[email protected]>
    ├── mongo-swift-driver<https://github.com/mongodb/[email protected]>
    │   ├── nimble<https://github.com/Quick/[email protected]>
    │   ├── swift-nio<https://github.com/apple/[email protected]>
    │   │   ├── swift-atomics<https://github.com/apple/[email protected]>
    │   │   └── swift-collections<https://github.com/apple/[email protected]>
    │   ├── swift-bson<https://github.com/mongodb/[email protected]>
    │   │   ├── swift-nio<https://github.com/apple/[email protected]>
    │   │   │   ├── swift-atomics<https://github.com/apple/[email protected]>
    │   │   │   └── swift-collections<https://github.com/apple/[email protected]>
    │   │   ├── swift-extras-json<https://github.com/swift-extras/[email protected]>
    │   │   ├── swift-extras-base64<https://github.com/swift-extras/[email protected]>
    │   │   └── nimble<https://github.com/Quick/[email protected]>
    │   └── swift-atomics<https://github.com/apple/[email protected]>
    └── vapor<https://github.com/vapor/[email protected]>
        ├── async-http-client<https://github.com/swift-server/[email protected]>
        │   ├── swift-nio<https://github.com/apple/[email protected]>
        │   │   ├── swift-atomics<https://github.com/apple/[email protected]>
        │   │   └── swift-collections<https://github.com/apple/[email protected]>
        │   ├── swift-nio-ssl<https://github.com/apple/[email protected]>
        │   │   └── swift-nio<https://github.com/apple/[email protected]>
        │   │       ├── swift-atomics<https://github.com/apple/[email protected]>
        │   │       └── swift-collections<https://github.com/apple/[email protected]>
        │   ├── swift-nio-http2<https://github.com/apple/[email protected]>
        │   │   ├── swift-nio<https://github.com/apple/[email protected]>
        │   │   │   ├── swift-atomics<https://github.com/apple/[email protected]>
        │   │   │   └── swift-collections<https://github.com/apple/[email protected]>
        │   │   └── swift-atomics<https://github.com/apple/[email protected]>
        │   ├── swift-nio-extras<https://github.com/apple/[email protected]>
        │   │   └── swift-nio<https://github.com/apple/[email protected]>
        │   │       ├── swift-atomics<https://github.com/apple/[email protected]>
        │   │       └── swift-collections<https://github.com/apple/[email protected]>
        │   ├── swift-nio-transport-services<https://github.com/apple/[email protected]>
        │   │   ├── swift-nio<https://github.com/apple/[email protected]>
        │   │   │   ├── swift-atomics<https://github.com/apple/[email protected]>
        │   │   │   └── swift-collections<https://github.com/apple/[email protected]>
        │   │   └── swift-atomics<https://github.com/apple/[email protected]>
        │   ├── swift-log<https://github.com/apple/[email protected]>
        │   └── swift-atomics<https://github.com/apple/[email protected]>
        ├── async-kit<https://github.com/vapor/[email protected]>
        │   ├── swift-nio<https://github.com/apple/[email protected]>
        │   │   ├── swift-atomics<https://github.com/apple/[email protected]>
        │   │   └── swift-collections<https://github.com/apple/[email protected]>
        │   └── swift-log<https://github.com/apple/[email protected]>
        ├── console-kit<https://github.com/vapor/[email protected]>
        │   └── swift-log<https://github.com/apple/[email protected]>
        ├── swift-crypto<https://github.com/apple/[email protected]>
        ├── routing-kit<https://github.com/vapor/[email protected]>
        │   └── swift-log<https://github.com/apple/[email protected]>
        ├── swift-backtrace<https://github.com/swift-server/[email protected]>
        ├── swift-nio<https://github.com/apple/[email protected]>
        │   ├── swift-atomics<https://github.com/apple/[email protected]>
        │   └── swift-collections<https://github.com/apple/[email protected]>
        ├── swift-nio-ssl<https://github.com/apple/[email protected]>
        │   └── swift-nio<https://github.com/apple/[email protected]>
        │       ├── swift-atomics<https://github.com/apple/[email protected]>
        │       └── swift-collections<https://github.com/apple/[email protected]>
        ├── swift-nio-http2<https://github.com/apple/[email protected]>
        │   ├── swift-nio<https://github.com/apple/[email protected]>
        │   │   ├── swift-atomics<https://github.com/apple/[email protected]>
        │   │   └── swift-collections<https://github.com/apple/[email protected]>
        │   └── swift-atomics<https://github.com/apple/[email protected]>
        ├── swift-nio-extras<https://github.com/apple/[email protected]>
        │   └── swift-nio<https://github.com/apple/[email protected]>
        │       ├── swift-atomics<https://github.com/apple/[email protected]>
        │       └── swift-collections<https://github.com/apple/[email protected]>
        ├── swift-log<https://github.com/apple/[email protected]>
        ├── swift-metrics<https://github.com/apple/[email protected]>
        ├── swift-algorithms<https://github.com/apple/[email protected]>
        │   └── swift-numerics<https://github.com/apple/[email protected]>
        ├── websocket-kit<https://github.com/vapor/[email protected]>
        │   ├── swift-nio<https://github.com/apple/[email protected]>
        │   │   ├── swift-atomics<https://github.com/apple/[email protected]>
        │   │   └── swift-collections<https://github.com/apple/[email protected]>
        │   ├── swift-nio-ssl<https://github.com/apple/[email protected]>
        │   │   └── swift-nio<https://github.com/apple/[email protected]>
        │   │       ├── swift-atomics<https://github.com/apple/[email protected]>
        │   │       └── swift-collections<https://github.com/apple/[email protected]>
        │   ├── swift-nio-transport-services<https://github.com/apple/[email protected]>
        │   │   ├── swift-nio<https://github.com/apple/[email protected]>
        │   │   │   ├── swift-atomics<https://github.com/apple/[email protected]>
        │   │   │   └── swift-collections<https://github.com/apple/[email protected]>
        │   │   └── swift-atomics<https://github.com/apple/[email protected]>
        │   └── swift-atomics<https://github.com/apple/[email protected]>
        └── multipart-kit<https://github.com/vapor/[email protected]>
            ├── swift-nio<https://github.com/apple/[email protected]>
            │   ├── swift-atomics<https://github.com/apple/[email protected]>
            │   └── swift-collections<https://github.com/apple/[email protected]>
            └── swift-collections<https://github.com/apple/[email protected]>

  1. What version of MongoDB are you using? (Check with the MongoDB shell using db.version())
    6.0.2
  2. What is your MongoDB topology (standalone, replica set, sharded cluster, serverless)?
    standalone

Describe the bug

running the App test provided in the template by calling swift test ends up with the following error;

Building for debugging...
Build complete! (0.89s)
Test Suite 'All tests' started at 2023-04-09 09:24:37.824
Test Suite 'VaporExamplePackageTests.xctest' started at 2023-04-09 09:24:37.825
Test Suite 'AppTests' started at 2023-04-09 09:24:37.825
Test Case '-[AppTests.AppTests testFetchKittens]' started.
MongoSwift/MongoClient.swift:398: Assertion failed: MongoClient was not closed before deinitialization. Please call `close()` or `syncClose()` when the client is no longer needed.
error: Exited with signal code 5

BE SPECIFIC:

  • What is the expected behavior and what is actually happening?
  • Do you have any particular output that demonstrates this problem?
  • Do you have any ideas on why this may be happening that could give us a
    clue in the right direction?
  • Did this issue arise out of nowhere, or after an update (of the driver,
    server, and/or Swift)?
  • Are there multiple ways of triggering this bug (perhaps more than one
    function produce a crash)?
  • If you know how to reproduce this bug, please include a code snippet here:

To Reproduce
Steps to reproduce the behavior:

  1. checkout the code at [email protected]
  2. remove all leaf code and imports (couldnt get that to compile)
  3. run swift test

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.