ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / Managing databases / Big Data / Managing Mongo data files
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Adds one or more documents into a collection of MongoDB database.
Example
cnxMDB is mongoConnection
MongoAdd(cnxMDB.Database["CRM"].Collection["MaCollection"], ...
	 "{ ""nom"" :""paul"", ""taille"" : 182 }")
gclCollection is mongoCollection
// Variable contenant les documents à ajouter dans la base
tabDocument is array of strings
// Variables temporaires
stContact is STInfoContact
sBufferJSON is string

// Construction du tableau des documents
stContact = [ "MOITOU", "Elodie", "+33.467032032", "e.moitou@windev.com" ]
Serialize(stContact, sBufferJSON, psdJSON)
Add(tabDocument, sBufferJSON)
stContact = [ "SMITH", "Robert", "+33.467032032", "r.smith@windev.com" ]
Serialize(stContact, sBufferJSON, psdJSON)
Add(tabDocument, sBufferJSON)
stContact = [ "HUDSON", "Jade", "+33.467032032", "j.hudson@windev.com" ]
Serialize(stContact, sBufferJSON, psdJSON)
Add(tabDocument, sBufferJSON)

// Ajout des trois contacts en un seul appel
MongoAdd(gclCollection, tabDocument)
Syntax

Adding a document into a collection Hide the details

<Result> = MongoAdd(<Collection> , <Document> [, <Option>])
<Result>: Boolean
  • True if the operation was performed,
  • False if a problem occurs. ErrorInfo is used to identify the error.
<Collection>: mongoCollection variable
Name of the mongoCollection variable that represents the collection in which the document will be added.
<Document>: Type corresponding to the document
Document that will be added to the collection. This document can be:
  • a document in JSON format. In this case, this parameter corresponds to a character string.
  • a document in BSON format. In this case, this parameter corresponds to a buffer.
  • a variant.
<Option>: Optional Integer constant
Option for adding the document:
mongoWithoutValidationUsed to add the document without checking the document structure.

Adding a list of documents into a collection Hide the details

<Result> = MongoAdd(<Collection> , <List of documents> [, <Options>])
<Result>: Boolean
  • True if the operation was performed,
  • False if a problem occurs. ErrorInfo is used to identify the error.
<Collection>: mongoCollection variable
Name of the mongoCollection variable that represents the collection in which the documents will be added.
<List of documents>: Array
Array of documents that will be added to the collection. These documents can correspond to:
  • a document in JSON format. In this case, this parameter corresponds to a character string.
  • a document in BSON format. In this case, this parameter corresponds to a buffer.
  • a variant.
<Options>: Optional Integer constant
Options for adding documents:
mongoContinueIfErrorUsed to add the next document even if the previous document triggered an error.
mongoWithoutValidationUsed to add the document without checking the document structure.
Related Examples:
Native access to MongoDB Unit examples (WINDEV): Native access to MongoDB
[ + ] This example shows how to use the main functions of native access to MongoDB databases: adding data, reading (searching), modifying and deleting data in the database. The example also shows functions for saving files in the MongoDB GridFS data system.
Component: wd300big.dll
Minimum version required
  • Version 22
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 03/27/2025

Send a report | Local help