PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Adds one or more documents into a collection of MongoDB database.
Example
MongoAdd(cntMDB..Database["CRM"]..Collection["MyCollection"], ...
 "{ ""name"":""paul"", ""size"" : 182 }")
// Variable containing the documents that will be added into the database
arrDocument is array of strings

// Temporary variables
stContact is STContactInfo
sJSONBuffer is string

// Build the array of documents
stContact = [ "MOORE", "Ellen", "+33.467032032", "e.moore@windev.com" ]
Serialize(stContact, sJSONBuffer, psdJSON)
Add(arrDocument, sJSONBuffer)

stContact = [ "SMITH", "Robert", "+33.467032032", "r.smith@windev.com" ]
Serialize(stContact, sJSONBuffer, psdJSON)
Add(arrDocument, sJSONBuffer)

stContact = [ "HUDSON", "Jade", "+33.467032032", "j.hudson@windev.com" ]
Serialize(stContact, sJSONBuffer, psdJSON)
Add(arrDocument, sJSONBuffer)

// Add the three contacts in a single call
MongoAdd(gclCollection, arrDocument)
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 occurred. ErrorInfo is used to identify the error.
<Collection>: mongoCollection variable
Name of mongoCollection variable representing the collection into which the document will be added..
<Document>: Type corresponding to the document
Document that will be added to the collection. This document 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.
<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 occurred. ErrorInfo is used to identify the error.
<Collection>: mongoCollection variable
Name of mongoCollection variable representing the collection into 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.
Components
WINDEVWEBDEV - Server codeReports and Queries wd230big.dll
Minimum required version
  • Version 22
This page is also available for…
Comments
Click [Add] to post a comment