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');
also, if want prop of skill object, example "value", can this:
db.collection.distinct('skills.value');
hope helps.
Comments
Post a Comment