AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Ayuda / WLanguage / Administrar bases de datos / Big Data / Gestión de archivos Mongo
  • Creating a collection
MongoCreateCollection (Example)
Creating a collection
This example shows how to connect to a database. The database is created if it does not exist.
gclConnection is mongoConnection
gclDataBase is mongoDatabase
 
// Connect to the MongoDB server on the example database (creates the database if it does not exist)
gclConnection = MongoCreate(StringBuild("mongodb://%1:%2/%3", EDT_ServerAddress, ...
EDT_Port, DATABASE_WINDEV_EXAMPLE))
// Retrieve the object for accessing the database
gclDataBase = gclConnection.Database[DATABASE_WINDEV_EXAMPLE]
 
 
// Search the collection of examples
gclCollection = gclDataBase.Collection[COLLECTION_WINDEV_EXAMPLE]
 
// Create the collection of examples if it does not exist
IF gclCollection = Null THEN
cOption is mongoCollectionOption
// Options used to limit the collection size
// cOption.MaxSize: If the collection reaches or exceeds this size (in bytes),
// the oldest elements will be deleted
// cOption.MaxNbDocument: If the collection reaches or exceeds this size
// in number of documents,
// the oldest elements will be deleted
 
// Validate the added documents
// cOption.Validator: JSON document describing the format of added documents
// This example of validator checks whether the document contains
// at least the Phone item or the Email item
cOption.Validator = "{ ""$or"": [{""Phone"": {""$type"": ""string"" } }," + ...
"{ ""Email"": {""$type"": ""string"" } } ] }"
// cOption.ValidationLevel: Defines how the validator is used.
// The possible values are:
// "off": does not use the validator
// "strict": uses the validator for the additions and the modifications
// "moderate": uses the validator for the additions,
// uses the validator in modification only if the modified document is valid
cOption.ValidationLevel = "strict"
 
MongoCreateCollection(gclBase, COLLECTION_WINDEV_EXAMPLE, cOption)
 
gclCollection = gclDataBase.Collection[COLLECTION_WINDEV_EXAMPLE]
END
Versión mínima requerida
  • Versión 22
Esta página también está disponible para…
Comentarios
Haga clic en [Agregar] para publicar un comentario

Última modificación: 27/05/2022

Señalar un error o enviar una sugerencia | Ayuda local