Retrieving all documents without iterating the cursor using mongo driver

Mendes

I'm using the mongo driver together with NodeJs to retrieve database collections.

Here is a simple code to get all users:

const getUsers = async context => {
    let users = await db.collection("users");

    let result = await users.find({
        deletedAt: null
    });

    console.log(result)
    return result
};

The result is a cursor that needs to be iterated.

Is there a way to retrieve all records without the need of iterating, something like toArray() or toJSON() ?

mickl

You can use .toArray() as you expect (docs):

To get all documents at once, users can use the toArray method.

const getUsers = async context => {
    let users = await db.collection("users");

    let cursor = users.find({
        deletedAt: null
    });

    let result = await cursor.toArray();

    console.log(result)
    return result
};

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Find all documents in a collection with mongo go driver

分類Dev

convert result into JSON without structs using mongo-go-driver

分類Dev

Iterating and retrieving metadata of all objects in Amazon S3

分類Dev

Get all documents from mongo collection using a nested list comprehension in Python

分類Dev

Get all documents from mongo collection using a nested list comprehension in Python

分類Dev

Impute entire DataFrame (all columns) using Scikit-learn (sklearn) without iterating over columns

分類Dev

Rotating cursor without using WinForms

分類Dev

MongoDB retrieving data from inner classes. Using mongo template

分類Dev

How to unset a field from all documents with php mongo adapter?

分類Dev

Retrieving the documents connected this vertex

分類Dev

Documents not expiring using TTL in mongodb 3.0 (.Net driver 2.0)

分類Dev

C# Mongo driver: Update query using joins and UpdateManyAsync

分類Dev

Firebase aggregate values over property without fetching all relevant documents

分類Dev

Mongo DB, count documents

分類Dev

Using the result of a CTE to query from table without cursor

分類Dev

H2o: Iterating over data bigger than memory without loading all data into memory

分類Dev

Retrieving error status from Haskell MongoDB driver

分類Dev

Storing Date objects in mongo and retrieving and comparing them

分類Dev

How to use the elements of a slice in bson.A using mongo-go-driver 0.2.0

分類Dev

How to run MongoDB native query (JSON) using Mongo-Java Driver?

分類Dev

displaying iterating numbers without sum

分類Dev

Getting integer in HashMap without Iterating

分類Dev

Pandas: ValueError iterating using `at`

分類Dev

Retrieving model using mongoose

分類Dev

Camel recipientList not iterating all recipients

分類Dev

Is using a structure without all members assigned undefined?

分類Dev

SQL Server cursor type of run (without cursor?)

分類Dev

How to drop duplicate documents of a sharded indices in mongo?

分類Dev

javascript check if value is a mongo.cursor

Related 関連記事

  1. 1

    Find all documents in a collection with mongo go driver

  2. 2

    convert result into JSON without structs using mongo-go-driver

  3. 3

    Iterating and retrieving metadata of all objects in Amazon S3

  4. 4

    Get all documents from mongo collection using a nested list comprehension in Python

  5. 5

    Get all documents from mongo collection using a nested list comprehension in Python

  6. 6

    Impute entire DataFrame (all columns) using Scikit-learn (sklearn) without iterating over columns

  7. 7

    Rotating cursor without using WinForms

  8. 8

    MongoDB retrieving data from inner classes. Using mongo template

  9. 9

    How to unset a field from all documents with php mongo adapter?

  10. 10

    Retrieving the documents connected this vertex

  11. 11

    Documents not expiring using TTL in mongodb 3.0 (.Net driver 2.0)

  12. 12

    C# Mongo driver: Update query using joins and UpdateManyAsync

  13. 13

    Firebase aggregate values over property without fetching all relevant documents

  14. 14

    Mongo DB, count documents

  15. 15

    Using the result of a CTE to query from table without cursor

  16. 16

    H2o: Iterating over data bigger than memory without loading all data into memory

  17. 17

    Retrieving error status from Haskell MongoDB driver

  18. 18

    Storing Date objects in mongo and retrieving and comparing them

  19. 19

    How to use the elements of a slice in bson.A using mongo-go-driver 0.2.0

  20. 20

    How to run MongoDB native query (JSON) using Mongo-Java Driver?

  21. 21

    displaying iterating numbers without sum

  22. 22

    Getting integer in HashMap without Iterating

  23. 23

    Pandas: ValueError iterating using `at`

  24. 24

    Retrieving model using mongoose

  25. 25

    Camel recipientList not iterating all recipients

  26. 26

    Is using a structure without all members assigned undefined?

  27. 27

    SQL Server cursor type of run (without cursor?)

  28. 28

    How to drop duplicate documents of a sharded indices in mongo?

  29. 29

    javascript check if value is a mongo.cursor

ホットタグ

アーカイブ