-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathSample2.py
More file actions
42 lines (36 loc) · 1.44 KB
/
Sample2.py
File metadata and controls
42 lines (36 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""Following example works with Python Client"""
from ojai.types.ODate import ODate
from mapr.ojai.storage.ConnectionFactory import ConnectionFactory
"""Create a connection, get store, insert new document into store"""
# create a connection using path:user@password
connection_string = "localhost:5678?auth=basic;user=mapr;password=mapr;" \
"ssl=true;" \
"sslCA=/opt/mapr/conf/ssl_truststore.pem;" \
"sslTargetNameOverride=node.mapr.com"
connection = ConnectionFactory.get_connection(connection_str=connection_string)
# Get a store and assign it as a DocumentStore object
store = connection.get_store(store_path="/sample_store1")
# Json string or json dictionary
json_dict = {"_id": "id002",
"name": "Joe",
"age": 50,
"address": {
"street": "555 Moon Way",
"city": "Gotham"}
}
# Json string or json dictionary
payment = {"payment_method": "card",
"name": "visa",
"card_info": {
"number": "1234 1234 1234 1234",
"exp_date": ODate.parse("2022-10-24"),
"cvv": 123}
}
# Create new document from json_document
new_document = connection.new_document(dictionary=json_dict)
# Add nested dictionary into document
new_document.set(field_path='payment', value=payment)
# Insert or replace new document into the store
store.insert_or_replace(doc=new_document)
# close
connection.close()