find()

Creates a cursor for a filter that can be used to iterate over results

Example

//find all items in db
db.collection("users").find({}).then(items => {
    console.log(items);
    //output => [{item1...}, {item2...}, {item3...}];
}).catch(error => {
    console.log("error:", error);
});

//find items by filter
db.collection("users").find({
    banned: false,
    accountCreated: "13/02/2023"
}).then(items => {
    console.log(items);
    /*
        items output => [
            {
                _id: "t4m1s8kuw3445ros7zz682no52e9lj91",
                banned: false,
                accountCreated: "13/02/2023",
                example1: "example1",
                example2: "example2",
            },
            {
                _id: "dvf567m6psu73fqhre711133i13ant7m",
                banned: false,
                accountCreated: "13/02/2023",
                example1: "example1",
                example2: "example2",
            }
        ];
    */
}).catch(error => {
    console.log("error:", error);
});

find(<filter>)

Last updated