-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Uwe Fetzer edited this page Sep 5, 2013
·
2 revisions
DATA: connection TYPE REF TO zcl_mongo_connection,
db TYPE REF TO zcl_mongo_db,
collection TYPE REF TO zcl_mongo_collection,
scarr_t TYPE STANDARD TABLE OF scarr.
SELECT * FROM scarr
INTO TABLE scarr_t.
connection = zcl_mongo_connection=>connect( '192.168.38.56' ).
db = connection->db( 'sap' ).
collection = db->collection( 'scarr' ).
collection->insert( scarr_t ).
You can always check the results with the mongo DB interactive shell ("./mongo"):
> use sap
switched to db sap
> db.scarr.find()
{ "_id" : ObjectId("4f37a5ec476ef70158000000"), "mandt" : "001", "carrid" : "AA"
, "url" : "http://www.aa.com", "currcode" : "USD", "carrname" : "American Airlin
es" }
{ "_id" : ObjectId("4f37a5ec476ef70158000001"), "mandt" : "001", "carrid" : "AB"
, "url" : "http://www.airberlin.de", "currcode" : "EUR", "carrname" : "Air Berli
n" }
...
Get as ABAP data:
collection->find( IMPORTING data = scarr_t ).
Get as JSON string:
collection->find( IMPORTING result = result ).
Get one record:
DATA: scarr_s TYPE scarr.
collection->find_one(
EXPORTING
criteria = '{"carrid":"LH"}'
IMPORTING
data = scarr_s
).
The database cursor is set automatically. If more than one record matches the criteria you can read the next record with "find_more( )" in a loop.
collection->update(
EXPORTING
criteria = '{"carrid":"LH"}'
newobj = '{"$set":{"url":"http://www.se38.de"}}'
).
You pass the whole object (as JSON) or use the following modifier operations (see docu on http://www.mongodb.org/display/DOCS/Updating )
$inc
$set
$unset
$push
$pushAll
$addToSet and $each
$pop
$pull
$pullAll
$rename
$bit
Update using an ABAP object:
collection->update(
EXPORTING
criteria = '{"carrid":"LH"}'
data = scarr_s ).
result = collection->remove( '{"carrid":"LH"}' ).
entries = collection->count( ).
result = collection->distinct( 'carrid' ).
result = collection->group(
key = '"carrid":true'
reduce = 'prev.sumseats += doc.seatsmax - doc.seatsocc; if (doc.seatsocc == 0){ prev.nullseats++ };'
initial = '"sumseats":0,"nullseats":0'
condition = '"fldate":{"$gt":"20110101"}'
).
result = collection->drop( ).
result = db->cmd( '{"buildinfo":1}' ).
background:
- see http://www.mongodb.org/display/DOCS/Security+and+Authentication
- see http://www.mongodb.org/display/DOCS/Implementing+Authentication+in+a+Driver
result = db->auth( user = user password = password ).