ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / Managing databases / Big Data / Managing Mongo files
  • Performing a search in a MongoDB database
MongoFind (Example)
Performing a search in a MongoDB database
This example is used to perform a search according to specific criteria.
// Define the search filter
// Find the contacts whose email address ends by "windev.com"
// To do so, filter with a regular expression: @windev\.com$
// The option 'i' is used to specify that the search will not be case sensitive
sFilter is string = [
{
"Email": {
"$regex": "@windev.com$",
"$options": "i"
}
}
]
 
// Define the search options
clOption is mongoFindOption
 
// clOption.Projection: Criterion for presenting documents
// (the controls that will be retrieved for example)
// We want to retrieve the LastName and FirstName items
// therefore an inclusion projection is done
// (specify the items to retrieve)
clOption.Projection = "{ ""LastName"": 1, ""FirstName"": 1 }"
// If we wanted to retrieve all the items EXCEPT for the phone,
// an exclusion projection could be performed:
// clOption.Projection = "{ Phone: 0 }"
 
// clOption.Limit: Maximum number of documents to return
// Retrieve up to 10 documents
clOption.Limit = 10
 
// clOption.Sort: Sort criterion of returned documents
clOption.Sort = ""
 
// clOption.Ignore: Exclusion criterion,
// the documents that match this criterion are ignored
clOption.Ignore = ""
 
// Starts the search and displays all the documents found in the trace
r is mongoResult dynamic = MongoFind(gclCollection, sFilter, clOption)
 
TableDeleteAll(TABLE_Contacts)
 
// To read all the documents, don't specify any search filter
FOR EACH v OF r
v2 is Variant = v
TableAddLine(TABLE_Contacts, v2.LastName, v2.FirstName, v2.Phone, v2.Email)
END
Minimum version required
  • Version 22
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 05/26/2022

Send a report | Local help