0

I have a large data set that's structured like this:

[
  Person1: { Mid: 0, Support: 0, Jungle: 0, Top: 0, Bot: 0 },
  Person2: { Mid: 0, Support: 0, Jungle: 0, Top: 0, Bot: 0 },
  Person3: { Mid: 0, Support: 0, Jungle: 0, Top: 0, Bot: 0 },
]

My schema looks something like this:

const rankSchema = new Schema(
  {
    rank: Schema.Types.Mixed,
    lastUpdated: { type: Date, default: Date.now() },
  },
  { minimize: false }
);

I have also tried:

{
    rank: [],
    lastUpdated: { type: Date, default: Date.now() },
},
// and also
 {
    rank: { type: Schema.Types.Mixed },
    lastUpdated: { type: Date, default: Date.now() },
  },

But nothing I do seems to be working. I am starting to think that storing information like this is not possible so what would be the best way to structure my data so that I won't have to loop through the entire array to find a specific person.

Edit: For clarification, I am trying to store that entire data set in the "rank" value of the schema.

2
  • is that even a valid format? should it be like [{Person1:{..}},{Person2:{..}},...] Commented Jul 9, 2020 at 3:39
  • @KarlL Will I be be able to look up each person without having to loop through each object in the way you're talking about? I guess I'll have to find a different way if my format isn't possible. Commented Jul 9, 2020 at 3:42

1 Answer 1

0

You can format your data like this:

let  data = {
  Person1: { Mid: 0, Support: 0, Jungle: 0, Top: 0, Bot: 0 },
  Person2: { Mid: 0, Support: 0, Jungle: 0, Top: 0, Bot: 0 },
  Person3: { Mid: 0, Support: 0, Jungle: 0, Top: 0, Bot: 0 }
}

Then you can access it by property like:

data.Person1, data.Person2 ...

also you can just use Object as the type for 'rank' field, then you can store your data into that field directly

const rankSchema = new Schema(
  {
    rank: {type: Object}
    lastUpdated: { type: Date, default: Date.now() },
  },
  { minimize: false }
);
Sign up to request clarification or add additional context in comments.

2 Comments

I originally had it this way but it made it really difficult to query each separate person and thought making it an array would be easier. I will switch back to that since it still works.
Was stuck with this same question. Thanks for your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.