I am new to mongoDB, and was wondering if the following is possible.
I have two different collection in the same mongo db table - called jobs
and nodes
and this is that they look like:
function testing() {
nodes.find(function(err, data) {
if (err) {
console.log(err)
} else {
console.log('NODES RETURNED: ', data)
jobs.find(function(err, post) {
if (err) {
console.log(err)
} else {
console.log('JOBS RETURNED: ', post)
}
});
}
});
}
Which returns the following:
JOBS RETURNED: [ { _id: '5899999354d59',
job_url: 'http://222.22.22.22:2222/jobs',
progress: 0,
queue: 0 },
{ _id: '5899b7d054da96',
job_url: 'http://111.11.1.111:1111/jobs',
progress: 0,
queue: 0 } ]
CLUSTER NODESS RETURNED: [ { _id: '58a9a4805c1f',
node_url: 'http://222.22.22.22:2222/nodes',
cpu: 40 },
{ _id: '58999a9a4805c23',
node_url: 'http://111.11.1.111:1111/nodes',
average_cpu: 15 } ]
So as you can see, the two different collections both have two documents each, and they can relate by the job_url and the node_url e.g. 222.22.22.22:2222
Is it possible for me to join the documents together based on this, so that the final result is something like this:
[ { _id: '58a9a4805c1f',
node_url: 'http://222.22.22.22:2222/nodes',
job_url: 'http://222.22.22.22:2222/jobs',
progress: 0,
queue: 0 },
cpu: 40 },
{ _id: '58999a9a4805c23',
node_url: 'http://111.11.1.111:1111/nodes',
job_url: 'http://111.11.1.111:1111/jobs',
progress: 0,
queue: 0,
average_cpu: 15 }
Any help / tips would be really appreciated!