Mongodb query

  mongodb, question

The middleware uses npInstallMongoDB-save-dev

Query the last a:1
collection.find({a:1}).toArray(function(err, docs){


However, I think this is problematic. This has read all a:1, which is very wasteful. Does this middleware have various query methods? Ask for a connection to watch it (Baidu has many se methods)

The main reason is that I don’t know what this middleware is called, how to find documents, and how to find a document.

When you installed mongodb using npm, you said you didn’t know what the middleware was called, uh, exactly, it was called driver.

npm install mongodb --save-dev

Correct a bit –save-dev means adding mongodb to dev dependency, but in fact it is a development dependency and should be-save


Since it is known that npm is used and mongodb is installed, it is better to use npm+mongodb as keyword combination search directly, and Google search is recommended.

The first one found in the search results is generally npm’s official website.

Then follow the steps to find doc
collection find

If you still don’t understand the above, then there are probably the following reasons.

  • English is not good. Seeing a pile of words that cannot find documents in English, I naturally cannot find official documents.

  • No search engine will be used to search for technical problems. Google search is preferred for technical problems, refine the problem and find several keywords.

  • Lazy

I wrote an article on how to search for technical problems.ArticleIf you are interested, you can have a look.