Comments (4)
Also putting a nicer error for: https://github.com/vapor/mongo-driver/blob/master/Sources/Filter%2BMongoKitten.swift#L55 would be nice.
from mongo-driver.
@tannernelson this can be solved another way too.
So if you store the ObjectId (or other ID that you're using) in the Document of the model and your model knows what collection you're referencing to. Let's say the PrivateMessage
object referencing to User
object. This Model (privatemessage) knows that it's referencing a User model, thus it can be resolved that way. It costs an extra query. Alternatively you can store a https://docs.mongodb.com/manual/reference/database-references/#dbrefs and resolve that automatically. I've already added support for DBRefs in the upcoming MongoKitten, but it's not difficult at all to implement
from mongo-driver.
{
$lookup:
{
from: <collection to join>,
localField: <field from the input documents>,
foreignField: <field from the documents of the "from" collection>,
as: <output array field>
}
}
Looks like this is how to do it.
http://stackoverflow.com/questions/2350495/how-do-i-perform-the-sql-join-equivalent-in-mongodb
let pipeline: AggregationPipeline = [
.lookup(fromCollection: String, localField: String, foreignField: String, as: String)
]
from mongo-driver.
Yup. It's already supported in MongoKitten. Please note that this is a feature requiring MongoDB 3.2 or above. MongoKitten will throw an error if this is used on lower versions.
from mongo-driver.
Related Issues (20)
- Vapor's TLS as MongoTCP connection HOT 1
- Readme not clear HOT 4
- Limit not working HOT 2
- "id" not populated on first save HOT 2
- Modify is not working properly HOT 7
- Future improvements
- Issue with vapor relationships and fluent
- Fluent siblings relationship count always returns zero HOT 1
- Doesn't support queries with multiple joins HOT 1
- Sum - aggregate query unsupported HOT 1
- Average - aggregate query unsupported HOT 1
- Min - aggregate query unsupported HOT 1
- Max - aggregate query unsupported HOT 1
- Computed properties are unsupported
- Custom - aggregate query unsupported
- Update to MongoKitten 4.1.x HOT 9
- NotMasterNoSlaveOk
- [Bug] Array of Arrays encoding doesn't work
- SwiftPM cannot resolve HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongo-driver.