Comments (7)
Taking another look at this issue, it hit me that a collection abstraction is not necessary at all if we are willing to break a bit of MongoDB convention. The from
field can refer directly to the join collection.
Example:
{
$lookup:
{
from: <collection to join>, // this will be an Array
localField: <field from the input documents>,
foreignField: <field from the documents of the "from" collection>,
as: <output_field>
}
}
In fact this is similar to what @justsml suggested above but will put the implementation of data sourcing outside of Mingo.
If a Function
value is used for the from
field, it will be called when the pipeline stage is reached to obtain the data to use. This is nice for a lazy effect and allows us to pass in values should we choose, which then can impact what the function will yield for the join. The latter part (params to function) is yet to be considered thoroughly.
Any comments?
from mingo.
I have only looked at the $lookup
operator following your question and it seems to reference another collection to function. This is not particularly suitable for Mingo
which only works per collection without a full backing database.
Perhaps you can experiment with an implementation using the custom operators feature. Please feel free to send a PR
from mingo.
Yup, it works with two collections. For the first glance it does not match Mingo
but it makes aggregation pipeline much more powerful and expressive. It's the analog of join
from the SQL world.
from mingo.
This would be cool if data was provided through promises, then you could point to a restful URI wrapper to reference collections:
{$lookup: {
from: collection('/api/users?active=true'), // <-- promis-ey thing,
localField: "email",
foreignField: "username"
}
}
I'll play around with the custom operators...
from mingo.
I thought a lot about this and it seems it would be better if we have 'collection' abstraction in Mingo
. It would allow us to implement $lookup
as well as $out
and so on.
I understand that it is a big shift and leads to a lot of refactoring, but it looks like the only good solution. We might implement this seamless way. Without changing existing API. Just add something like this:
let usersData = [
// ...
]
let users = Mingo.collection('users', usersData)
users.find( ... )
users.aggregate( ... )
// let data = users.toArray() - to get the array back
// or
// let users = Mingo.collection('users') - if it already exists in Mingo
// and we just want to get a link
What do you think guys? It isn't a heavy solution, is it?
from mingo.
This did cross my mind a while ago but I was deterred from going with it. My concern is that it makes Mingo begin to look like a mini MongoDB database which I want to avoid as much as possible.
I believe someone mentioned a similar project minimongo
that attempts to do and also has that update support.
Once we begin to hold collection references it opens up a can of worms of rules regarding immutability guarantees etc. I feel that is more suitable for an adjacent project which perhaps uses Mingo for the querying.
Have you had any success implementing $lookup
as a custom operator?
You may have to modify the original structure a bit to make it work by passing in the extra collection. It is ok to break a few rules to get Mingo to work for its purpose so the result need not be exactly as in MongoDB.
Let's keep the discussion going. I think we will come to an acceptable solution.
Thanks for pushing.
from mingo.
Added in commit 6ae6509
Currently, the from
field must be an array.
from mingo.
Related Issues (20)
- Add support for $topN (aggregation) HOT 3
- Add support for $minN (aggregation) HOT 1
- Add support for $minN (array) HOT 1
- Add support for $maxN (array) HOT 1
- Add support for $maxN (aggregation) HOT 1
- Add support for $locf (aggregation)
- Add support for $cosh (expression) HOT 1
- Add support for $sinh (expression) HOT 1
- Possible breaking error in 6.1.1 `dateFromParts` HOT 1
- core.addOperators is missing HOT 1
- How does generator function for collection work? HOT 2
- Expressions in arithmetic operators are evaluated in a nested path HOT 2
- Projection not working properly for deep nested objects HOT 1
- $Reduce $Map Returning incorrect results and making other fields return undefined.
- Es6 Module build HOT 1
- [email protected] breaks CommonJS requires of files inside package HOT 20
- Issues with $let since 6.2.0 HOT 1
- Strange behaviour in $round HOT 3
- Wrong evaluation with `NaN` value HOT 4
- TypeError: CreateListFromArrayLike called on non-object HOT 10
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 mingo.