Code Monkey home page Code Monkey logo

Comments (4)

tanner0101 avatar tanner0101 commented on August 26, 2024

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.

Joannis avatar Joannis commented on August 26, 2024

@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.

tanner0101 avatar tanner0101 commented on August 26, 2024
{
   $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.

Joannis avatar Joannis commented on August 26, 2024

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)

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.