@@ -132,7 +132,7 @@ Although new API isn't compatible with the previous one, it comes with **many im
132132
133133
134134# ## **Coming soon, work in progress**
135- - Counters & Time Series
135+ - Time Series
136136 - Replication & ETL Commands
137137 - Streaming (ready, will be merged on v5.4 - https://github.com/ravendb/ravendb-python-client/pull/168)
138138
@@ -149,6 +149,7 @@ Although new API isn't compatible with the previous one, it comes with **many im
149149 [Suggestions](# suggestions),
150150 [Patching](# advanced-patching),
151151 [Subscriptions](# subscriptions),
152+ [Counters](# counters),
152153 [Using classes](# using-classes-for-entities),
153154 [Working with secure server](# working-with-a-secure-server),
154155 [Building & running tests](# building)
@@ -1041,6 +1042,68 @@ with store.subscriptions.get_subscription_worker(SubscriptionWorkerOptions(subsc
10411042> <small>[can disable subscription](https:///github.com/ravendb/ravendb-python-client/blob/aa98bebc953561c4d5d1b94d4af809c9778137f7/ravendb/tests/jvm_migrated_tests/client_tests/subscriptions_tests/test_basic_subscription.py#L540-L549)</small>
10421043> <small>[can delete subscription](https:///github.com/ravendb/ravendb-python-client/blob/aa98bebc953561c4d5d1b94d4af809c9778137f7/ravendb/tests/jvm_migrated_tests/client_tests/subscriptions_tests/test_basic_subscription.py#L293-L309)</small>
10431044
1045+ ## Counters
1046+ There are many ways to play with counters. The most common path is to use session API ( ` session.counters_for()` ).
1047+ ` ` ` python
1048+
1049+ with store.open_session () as session:
1050+ user1 = User(" Aviv1" )
1051+ user2 = User(" Aviv2" )
1052+ session.store(user1, " users/1-A" )
1053+ session.store(user2, " users/2-A" )
1054+ session.save_changes ()
1055+
1056+ # storing counters via session API
1057+ with store.open_session () as session:
1058+ session.counters_for(" users/1-A" ).increment(" likes" , 100)
1059+ session.counters_for(" users/1-A" ).increment(" downloads" , 500)
1060+ session.counters_for(" users/2-A" ).increment(" votes" , 1000)
1061+
1062+ session.save_changes ()
1063+
1064+ # alternatively, loading counters via GetCountersOperation
1065+ counters = store.operations.send(GetCountersOperation(" users/1-A" , [" likes" , " downloads" ])).counters
1066+
1067+ # loading counters via session API
1068+ with store.open_session () as session:
1069+ user1_likes = session.counters_for(" users/1-A" ).get(" likes" )
1070+
1071+ # deleting counters via session API
1072+ with store.open_session () as session:
1073+ session.counters_for(" users/1-A" ).delete(" likes" )
1074+ session.counters_for(" users/1-A" ).delete(" downloads" )
1075+ session.counters_for(" users/2-A" ).delete(" votes" )
1076+
1077+ session.save_changes ()
1078+ ` ` `
1079+
1080+
1081+ # #### Playing with counters using CounterBatchOperation
1082+ ` ` ` python
1083+
1084+ counter_operation = DocumentCountersOperation(document_id=" users/1-A" , operations=[])
1085+ counter_operation.add_operations(
1086+ CounterOperation(" Likes" , counter_operation_type=CounterOperationType.INCREMENT, delta=4)
1087+ )
1088+ counter_operation.add_operations(
1089+ CounterOperation(
1090+ " Shares" ,
1091+ counter_operation_type=CounterOperationType.INCREMENT,
1092+ delta=422,
1093+ )
1094+ )
1095+ counter_operation.add_operations(CounterOperation(" Likes" , counter_operation_type=CounterOperationType.DELETE))
1096+
1097+ counter_batch = CounterBatch(documents=[counter_operation])
1098+ results = self.store.operations.send(CounterBatchOperation(counter_batch))
1099+ ` ` `
1100+ > # #### Related tests:
1101+ > <small>[incrementing counters](https:///github.com/ravendb/ravendb-python-client/blob/df4e92fbcfb07872e1d7cc920bff5196d19a3aa7/ravendb/tests/session_tests/test_counters.py#L24-L38)</small>
1102+ > <small>[document counters operation](https:///github.com/ravendb/ravendb-python-client/blob/f5149b943959ffa4ad7afaeef07c17583b4cb2e6/ravendb/tests/jvm_migrated_tests/client_tests/counters_tests/test_counters_single_node.py#L18-L61)</small>
1103+ > <small>[including counters](https:///github.com/ravendb/ravendb-python-client/blob/305459fbc4ba36c838a7fbde2b98d88d3aefa482/ravendb/tests/jvm_migrated_tests/client_tests/indexing_tests/counters_tests/test_basic_counters_indexes_strong_syntax.py#L29)</small>
1104+ > <small>[counters indexes](https:///github.com/ravendb/ravendb-python-client/blob/4ac192652bf57d304e1b48032d9acee56f2590b8/ravendb/tests/counters_tests/test_query_on_counters.py#L683)</small>
1105+
1106+
10441107## Using classes for entities
10451108
104611091. Define your model as class.
0 commit comments