0

I am wondering what is better to do. I have a pulled back a query like this:

Array
(
[_id] => MongoId Object
    (
        [$id] => 4eeedd9545c717620a000007
    )
[field1] => ...
[field2] => ...
[field3] => ...
[field4] => ...
[field5] => ...
[field6] => ...

[votes] => Array
    (
        [whoVoted] => Array
            (
                [0] => 4f98930cb1445d0a7d000001
                [1] => 4f98959cb1445d0a7d000002
                [1] => 4f88730cb1445d0a7d000003
            )

    )

)

Which would be faster:

  1. Pull that entire array in 1 query and use in_array() to find the right id?
  2. Pull everything from the first query except the votes and then do another mongodb query to see if that id exist in the array?

2 Answers 2

1

It Depends on a lot of factors that I suggest you test but IMO most of the time it would be faster to just do 2 querys

Sign up to request clarification or add additional context in comments.

Comments

0

Depends on the size of the array being returned / searched.

Also different servers are doing the work, what do you mean by faster? At what scale?

1 Comment

right now the array is 200 but I expect it to jump up to more like 10,000. yes at scale

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.