Community version MongoDB data query issue

db.runCommand({find: ‘prism202402’,batchSize: 2000000})

This statement cannot query all the data, there are over 200000 pieces of data in total, but using this command can only query more than 20000 pieces. How can I set this? Thank you

Hi @oyh_oyh and welcome to the community forum! :wave:

Firstly, if you are trying to use BatchSize in your query, the query should look like:

db.inventory.find({"fieldName": "prism202402"}).batchSize( 2000000)

We would need to gather more information on the above to understand your requirement or concerns in the above pots:

  1. Can you help me with the sample code where you are trying to use in the Java application?
  2. Can you provide details about the structure of the data you are querying?
  3. Have you tried running the correct queries directly in the MongoDB shell to see if the issue persists?


Hi @Aasawari I have tried using the db. inventory. find ({"fieldName": "prism202402"}) statement in the mongodb shell to query all data without any issues, but I cannot query all data using the db. runCommand ({find: 'prism202402'}) statement. But what if I just want to use db. runCommand ({find: 'prism202402'}) to query all data? How to handle it? thanks

If you want to use the runCommand you would probably need a lot more parameters to have the equivalent to your db.inventory.find().

First, in db.inventory.find(), there is a collection named inventory. It is not specified in your runCommand.

Then, in db.inventory.find(), there is a field named fieldName. It is not specified in your runCommand.

I do not know the runCOmmand but it would at least need to look like the following in order to be close to the find.

{ find : { fieldName : "prism202402" } , coll : "inventory" }

You might also need to explicitly specify the database with a db: field. But I would be surprised if the find: field is as simple as that. I suspect the it needs to be canonical like the parsedQuery you get when looking at the explain plan. Such as:

      fieldName: {
        '$eq': 'prism202402'

I am the feeling the db.inventory.find does indeed end up being a runCommand but with a lot of complexity that you will need to deal with your self.

I just found out, while I write here that 1. db.inventory.find is indeed a runCommand and from the explain plan it looks like:

    find: 'inventory',
    filter: {
      fieldName: 'prism202402'
    '$db': 'test'

But why would you wand to query using runCommand() rather than find()? It seems over complicated.


Hi @steevej
Are these two statements equivalent? Why is the total number of queries inconsistent,

Thank you for your answer just now

Please do not publish screenshot of code or sample documents. It is completely unusable. Read Formatting code and log snippets in posts so that we can work with what you publish.

According to the explain plan, they are not. If you insist in using a low level API like runCommand() rather than using the friendly find() you will have to

  1. get familiar with the explain plan so that you can see by yourself that your runCommand() is not correct
  2. share the code where you use runCommand() and the code were you use find() because the issue might be with how you use runCommand()
  3. give compelling reasons as to why you want to use the low level runCommand() rather than find().