From 060915188746554d8c40cd351f1e815cdf2159e6 Mon Sep 17 00:00:00 2001 From: Joannis Orlandos Date: Tue, 2 Jan 2018 14:18:42 +0100 Subject: [PATCH] more mongodb docs --- 3.0/docs/databases/mongodb/getting-started.md | 16 ++++----- 3.0/docs/databases/mongodb/interpreting.md | 34 +++++++++++++------ 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/3.0/docs/databases/mongodb/getting-started.md b/3.0/docs/databases/mongodb/getting-started.md index 533a8e39..58476c36 100644 --- a/3.0/docs/databases/mongodb/getting-started.md +++ b/3.0/docs/databases/mongodb/getting-started.md @@ -35,7 +35,7 @@ Use `import MongoKitten` to access the APIs. ## With Fluent -MySQL works well Fluent, you just need to make sure to add the [vapor/fluent-mysql](https://github.com/vapor/fluent-mysql) package to your project. +To use MongoDB with Fluent, you just need to make sure to add the [vapor/fluent-mongodb](https://github.com/vapor/fluent-mongodb) package to your project. To do this, add the Fluent MySQL package to your Package manifest. @@ -47,21 +47,21 @@ let package = Package( name: "Project", dependencies: [ ... - .package(url: "https://github.com/vapor/fluent-mysql.git", .revision("beta")), + .package(url: "https://github.com/vapor/fluent-mongodb.git", .revision("beta")), ], targets: [ - .target(name: "Project", dependencies: ["FluentMySQL", ... ]) + .target(name: "Project", dependencies: ["FluentMongoDB", ... ]) ] ) ``` If this is your first time adding a dependency, you should read our introduction to [Package.swift](../../getting-started/spm.md). -Use `import FluentMySQL` to access MySQL's Fluent compatible APIs. [Learn more about the Fluent APIs here](../../fluent/getting-started/provider.md) +Use `import FluentMongoDB` to access MongoDB's Fluent compatible APIs. [Learn more about the Fluent APIs here](../../fluent/getting-started/provider.md) -### Setting up services - -In order to set up MySQL with Fluent you first need to register the Fluent provider: + + More info on working with Fluent can be found [here](../../fluent/getting-started/getting-started.md). diff --git a/3.0/docs/databases/mongodb/interpreting.md b/3.0/docs/databases/mongodb/interpreting.md index 1cc8c3ec..e76621fe 100644 --- a/3.0/docs/databases/mongodb/interpreting.md +++ b/3.0/docs/databases/mongodb/interpreting.md @@ -77,12 +77,23 @@ For inserting you can use `insert` which have various parameters which you can u Most parameters have a default and can thus be left out of not needed. ```swift - +myCollection.insert([ + "_id": ObjectId(), + "some": "string", + "date": Date() +]) ``` ## Aggregates -If you followed this article you should know the basics of MongoKitten aggregates. If you, at any point, need a specific stage, you can look for the stage by the MongoDB name in the documentation or make use of autocomplete. -All aggregates can be quickly accessed using by simply typing a dot (.) inside the pipeline array literal like you would for enum cases. This will autocomplete to all available static functions that can help you create a stage. If you miss a stage or want to create a stage manually you can do so by providing a BSONDocument like this: +If you followed this article you should know the basics of MongoKitten aggregates. +If you, at any point, need a specific stage, you can look for the stage by the MongoDB name in the documentation or make use of autocomplete. + +All supported aggregates can be quickly accessed using by simply typing a dot (`.`) inside the pipeline array literal like you would for enum cases. +This will autocomplete to all available static functions that can help you create a stage. + +If you miss a stage or want to create a stage manually you can do so by providing a BSON `Document` like this: + +```swift let stage = Stage([ "$match": [ "username": [ @@ -90,18 +101,21 @@ let stage = Stage([ ] ] ]) +``` + The stage must be equal to the Document representation of the stage operators described here. You can then add this stage as one of the values in the array. -Queries -MongoDB queries can work if converted to a Document. If you do this, you must either use a literal query like below or write it using the query builder described here. + +## Document Queries + +MongoDB queries can work if converted to a Document. +If you do this, you must either use a literal query like below or write it using the query builder described here. + +```swift let query = Query(document) let literalQuery: Query = [ "age": [ "$gte": 15 ] ] -Sorting and Projecting -Sorts and projections have quite a bit of sugarcoating around them for readability and MongoDB-newcomers as explained here. -Both objects can be wrapped around a Document like you can with Query : -let sort = Sort(document) -let projection = Projection(document) +```