Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation: Join/Merge #541

Closed
Extarys opened this issue Feb 9, 2018 · 3 comments
Closed

Documentation: Join/Merge #541

Extarys opened this issue Feb 9, 2018 · 3 comments

Comments

@Extarys
Copy link

@Extarys Extarys commented Feb 9, 2018

How can I join 2 datasets and if possible sort them?

I'd like to join the artist_id from a song to the id of the artists dataset and sort the results by artists.

My previous code, before splitting things:

Database.table.Songs.find({}).sort({ artist: 1, album: 1 }, function(err, data) {
    cb(data)
});

The issue is that I might need to display all artists or all albums made by an artist and I think making a separate dataset for this is better.

What I would like

Database.table.Songs.find({}, function(err, data) {
            data.forEach(function(action) {
                Database.table.Artists.findOne({ _id: data.artist_id }, function (err, artist) {
                    cb(data);
                });
            });
});

or

Database.table.Songs.find({}).join(Database.table.Artists: {artist_id, _id}).sort({artist_name: 1}, function(err, data) {
            data.forEach(function(action) {
                Database.table.Artists.findOne({ _id: data.artist_id }, function (err, artist) {
                    cb(data);
                });
            });
});

Is this possible? the documentation doesn't cover this.

@JamesMGreene

This comment has been minimized.

Copy link
Contributor

@JamesMGreene JamesMGreene commented Feb 9, 2018

Sounds like you’re trying to treat NeDB as a relational database (SQL) rather than a document store (NoSQL). Not recommended... wrong paradigm.

@Extarys

This comment has been minimized.

Copy link
Author

@Extarys Extarys commented Feb 10, 2018

Hmm, well many NoSQL databases offer Joins ;) anyway thx

Edit: I have a db called Covers which contain images and putting this in every songs and albums would require a huge amount of disk space :\

@Extarys Extarys closed this Feb 10, 2018
@rayfoss

This comment has been minimized.

Copy link

@rayfoss rayfoss commented May 18, 2018

https://www.mongodb.com/blog/post/6-rules-of-thumb-for-mongodb-schema-design-part-1

Try some of those tips... you might need a separate log style collection, but performance should be very high with simultaneous requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.