Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

What does findasync return in mongodb query?


Asked by Kylian Lugo on Dec 08, 2021 MongoDB



FindSync returns an IAsyncCursor while FindAsync returns a task of IAsyncCursor. MongoDB returns a query result in batches, and the batch size will not exceed the maximum size of a BSON document.
Similarly,
FindSync and FindAsync both have two overloads with three parameters. Both FindSync and FindAsync are somewhat similar except that FindSync is synchronous and blocks until it's call is complete. FindSync returns an IAsyncCursor while FindAsync returns a task of IAsyncCursor.
Keeping this in consideration, db.collection.findOne(query, projection)¶. Returns one document that satisfies the specified query criteria on the collection or view. If multiple documents satisfy the query, this method returns the first document according to the natural order which reflects the order of documents on the disk.
Accordingly,
By default, queries in MongoDB return all fields in matching documents. To limit the amount of data that MongoDB sends to applications, you can include a projection document to specify or restrict fields to return. This page provides examples of query operations with projection using the db.collection.find () method in mongosh.
Thereof,
FindSync returns an IAsyncCursor while FindAsync returns a task of IAsyncCursor. MongoDB returns a query result in batches, and the batch size will not exceed the maximum size of a BSON document. As of version 3.2, the maximum size of a BSON document is 16 megabytes.