MongoDB the difference between db.getCollection.find and db.tablename.find?
Yes, they are exactly the same and you can use either.
The first form db.getCollection(collectionName).find()
becomes handy when your collection name contains special characters that will otherwise render the other syntax redundant.
Example:
Suppose your collection has a name that begin with _
or matches a database shell method or has a space, then you can use db.getCollection("booking trips").find()
or db["booking trips"].find()
where doing db.booking trips.find()
is impossible.