Extension::MongoDBBulkOperation Method
Syntax
c BulkOperation(C data)
Arguments
- data
JSON for the bulk operation
Description
Bulk add/remove/update record operation.
dim mongo as extension::MongoDB = extension::MongoDB::Create("mongodb://localhost:27017","TestDatabase","flowers")
mongo.BulkOperation(<<%json%
{
"insert" : true ,
"documents" : [
{
"Id": "00000000",
"Picture": "=filename_decode(\"Hires\\allium.jpg\")",
"Imagedate": "07/30/2001",
"Keywords": "allium white"
},
{
"Id": "00000001",
"Picture": "=filename_decode(\"Hires\\alyssum purple.jpg\")",
"Imagedate": "06/05/2002",
"Keywords": "alyssum purple"
},
{
"Id": "00000002",
"Picture": "=filename_decode(\"Hires\\anenome.jpg\")",
"Imagedate": "07/30/2001",
"Keywords": "anenome white"
},
{
"Id": "00000003",
"Picture": "=filename_decode(\"Hires\\anenomes.jpg\")",
"Imagedate": "05/24/2002",
"Keywords": "anenome white"
}
]
}
%json%)Bulk allows a lot of record inserts to be done at once, good for initailly populating collections.
Populate MongoDB from another DataSource
dim cn as sql::Connection
cn.Open("::Name::AADemo-Northwind")
dim tables as c = cn.ListTables()
for each table in tables
cn.PortableSQLEnabled = .t.
if cn.Execute("select * from "+table.value) then
dim rs as sql::ResultSet
rs = cn.ResultSet
dim json as c = rs.ToJSON()
dim mongo as extension::MongoDB = extension::MongoDB::Create("mongodb://localhost:27017","Northwinds",table.value)
mongo.BulkOperation("{ \"insert\" : true , \"documents\" : "+json+" }")
end if
nextThis example quickly populates mongo from the tables in Northwinds.