Topics   All   MacOS (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server   Client   Old   Deprecated   Guides   Examples   Videos
New in version: 11.1   11.2   11.3   11.4   11.5   12.0   12.1   12.2   12.3   12.4    Statistic    FMM    Blog  

MongoDB.Find

Query on collection, passing arbitrary query options to the server in options.

Component Version macOS Windows Linux Server iOS SDK
MongoDB 12.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "MongoDB.Find"; MongoDBRef; FilterJSON { ; OptionsJSON } )   More

Parameters

Parameter Description Example Flags
MongoDBRef The reference number for the mongo connection. $MongoDB
FilterJSON The JSON with filter details.
OptionsJSON The JSON with options. Optional

Result

Returns OK or error.

Description

Query on collection, passing arbitrary query options to the server in options.
Sets the current cursor.

See also find command documented here:
https://www.mongodb.com/docs/manual/reference/command/find/

Examples

Find records:

Set Variable [ $Mongo ; Value: MBS( "MongoDB.New" ) ]
Set Variable [ $r ; Value: MBS( "MongoDB.SetURI"; $Mongo; "mongodb://localhost/" ) ]
Set Variable [ $r ; Value: MBS( "MongoDB.Connect"; $Mongo) ]
Set Variable [ $r ; Value: MBS( "MongoDB.OpenDatabase"; $Mongo; "local" ) ]
Set Variable [ $r ; Value: MBS( "MongoDB.OpenCollection"; $Mongo; "test" ) ]
# get cursor for records describing collections
Set Variable [ $r ; Value: MBS( "MongoDB.Find"; $Mongo; "{\"Hello\": \"World\"}"; "{\"limit\": 10, \"sort\":{\"Hello\": -1}}") ]
If [ MBS("ISError") ]
    Show Custom Dialog [ "Failed to find" ; $r ]
Else
    # loop over records and show each
    Loop
        Set Variable [ $json ; Value: MBS( "MongoDB.CursorNext"; $Mongo) ]
        Exit Loop If [ MBS("IsError") // some error like connection dropped ]
        Exit Loop If [ Length ( $json ) = 0 // end of cursor ]
        Show Custom Dialog [ "Record" ; $json ]
    End Loop
End If
Set Variable [ $r ; Value: MBS( "MongoDB.Release"; $Mongo ) ]

Find records where OtherField > 123:

MBS( "MongoDB.Find"; $Mongo;
"{\"OtherField\": { \"$gt\" : 123}}")

See also

Release notes

  • Version 12.4
    • Added MongoDB.FindIndexes and MongoDB.Rename functions.

Example Databases

Created 22nd May 2022, last changed 24th May 2022


MongoDB.EstimatedDocumentCount - MongoDB.FindCollections

Feedback: Report problem or ask question.


Start Chat