javascript - Is there a way to merge two arrays into one single array in MongoDB? -


i'm kinda new in mongodb , i'm having trouble achieve task. i'll try explain it.

here collection:

'workers': [     {         _id: objectid(...),         name: 'john',         skills: [             { id: objectid('111'), value: 2 },             { id: objectid('222'), value: 3 },             { id: objectid('333'), value: 4 },         ]     },     {         _id: objectid(...),         name: 'mary',         skills: [             { id: objectid('222'), value: 5 },             { id: objectid('333'), value: 2 },             { id: objectid('444'), value: 3 },         ]     },     ... ] 

what i'm trying achieve this:

result: [     allskills: [         { id: objectid('111'), value: 2 },         { id: objectid('222'), value: 5 },         { id: objectid('333'), value: 4 },         { id: objectid('444'), value: 3 }     ] ] 

my result should single array skills inside workers collection (eventually i'll filter them).

in example, show final result, unique values , greater value each skill, i'm trying achieve here merge skills arrays single allskills array. now, i'm getting list of documents, each skills array.

thanks in advance.

something this?:

db.collection.distinct('skills'); 

distinct api docs here!

also, if want prop of skill object, example "value", can this:

db.collection.distinct('skills.value'); 

hope helps.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -