Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-2385

#count returns only first shard's collection when using 2 shards

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.0.10
    • Affects Version/s: None
    • Component/s: None
    • None

      I am using mongodb with 2 shard clusters and Mongoid 3.0.0.
      Each shard is a replica set of 3 machines.

      I configured shards yesterday and change mongoid.yml to point a mongos server.
      For shard test, I inserted 1,200,000 Phonebook models into sharded database using ruby script. (Running with rails runner command)
      Script ended successfully and shard key works well so there are 500,000 models in shard 1 and 700,000 models in shard 2.

      But when I'm using rails console, Phonebook.count returns only 500,000.
      In mongodb console, db.phonebooks.count() returns 1,200,000.

      So I checked mongos log, above two queries was different!
      Phonebook.count was logged
      single query: mongoid.$cmd { count: "phonebooks", query: {} } ntoreturn: -1 options : 4

      db.phonebooks.count() was logged
      single query: mongoid.$cmd { count: "phonebooks", query: {}, fields: {} } ntoreturn: -1 options : 0

      Can I make Phonebook.count() returns # of all shards collection?

      P.S
      I also tested destroy_all command in rails console.
      Phonebook.all.destroy_all returns 500,000 for result, but actually all phonebooks in two shards was removed. (1,200,000 models removed. )

            Assignee:
            Unassigned Unassigned
            Reporter:
            spica spica
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: