I have an array i want to push keys on each value and also want to count how many times they were repeated using aggregation

i have a document like this:

{
_id: 1
a: a
b: b
c: [
  1, 2, 3, 4, -4, -5, 6, 6
 ] 
}

now i want to use aggregate to make a new field "d: and in that field it will be an array of objects which will show all repeating values and how many they were repeat and if the value is negative like this should be result document.

{
_id: 1
a: a
b: b
c: [
  1, 2, 3, 4, -4, -5, 6, 6
 ] 
d: [{value: 1, timeShown: 1 , type: positive}, {value: 2, timeShown: 1, type: positive}, {value: 3, timeShown: 1, type: positive}, {value: 4, timeShown: 1, type: positive}, {value: -4, timeShown: 1, type: negative}, {value: -5, timeShown: 1, type: negative}, {value: 6, timeShown: 2, type: postive}]
}

Without using unwind, sort
because i have used sort too many times already i think it will take more RAM.

If you are going from one document to one document, then unwind should definitely NOT be used.

Here based on values in array c you want to create a new field d, right? Do something like this:

{$set:{ d: {$map:{
    input: {$setUnion:"$c"},
    as: "c",
    in: {
        value:"$$c",
        type:{$cond:{if:{$lt:["$$c",0]},then:"negative",else:"positive"}},
        timesShown:{$size:{$filter:{input:"$c", cond:{$eq:["$$c","$$this"]}}}}
    }
}}}})

What i want to use unwind and group because i have multiple documents.

Did you look at the {$set:{}} stage I showed? It does what you describe.

Multiple documents is fine - the question is are you trying to go from one set of documents to a different set or does every document basically map to one (new) document? Your example shows each document just getting a new field d which does not require any sort of unwinding or grouping.

Asya