# Best way to get previous Map data if put operation replaces existing data

**URL:** <https://discuss.aerospike.com/t/best-way-to-get-previous-map-data-if-put-operation-replaces-existing-data/5436>\
**Category:** Java Client\
**Created:** [August 8, 2018, 7:26pm UTC](https://discuss.aerospike.com/t/best-way-to-get-previous-map-data-if-put-operation-replaces-existing-data/5436 "2018-08-08T19:26:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mindstream](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/mindstream/32/969_2.png) [@mindstream](https://discuss.aerospike.com/u/mindstream)\
**Post date:** [August 8, 2018, 7:26pm UTC](https://discuss.aerospike.com/t/best-way-to-get-previous-map-data-if-put-operation-replaces-existing-data/5436/1 "2018-08-08T19:26:01Z")

</div>

I want to get the previous value from the map at a given map key when doing a _put_ operation. I could do a read first, but the extra network roundtrip overhead and the underlying cost of the server reading the map twice (one for each of these operations) is undesirable. I there a best practice for this scenario? Is there another way of accomplishing this other than a read before write? I was hoping I could send both Operations as a batch, but the documentation indicates that the read would happen AFTER the write, and I want it to happen BEFORE the write.

I’d love to be able to pass a MapReturnType to the put operation to indicate that I want the old data returned.

Any suggestions?

---

<div class="post-metadata">

**Author:** ![Brian](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/brian/32/2211_2.png) [@Brian](https://discuss.aerospike.com/u/Brian)\
**Post date:** [August 8, 2018, 8:50pm UTC](https://discuss.aerospike.com/t/best-way-to-get-previous-map-data-if-put-operation-replaces-existing-data/5436/2 "2018-08-08T20:50:52Z")

</div>

The server changed operation order from “write before read” to “in operation order” years ago. Can you point to the documentation which hasn’t been updated to reflect this?

---

<div class="post-metadata">

**Author:** ![mindstream](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/mindstream/32/969_2.png) [@mindstream](https://discuss.aerospike.com/u/mindstream)\
**Post date:** [August 8, 2018, 9:08pm UTC](https://discuss.aerospike.com/t/best-way-to-get-previous-map-data-if-put-operation-replaces-existing-data/5436/3 "2018-08-08T21:08:40Z")

</div>

You’re right, of course. I see it plainly stated on [https://www.aerospike.com/docs/client/nodejs/usage/kvs/multiops.html](https://www.aerospike.com/docs/client/nodejs/usage/kvs/multiops.html).

This statement toward the top confused me.  
_ **Aerospike provides the ability to perform multiple operations on a record within a single transaction. This feature allows modification of record bins, and then reads them back to the client within a single transaction. The application gets record status at transaction completion.** _

I should have read further.

Thanks for clarifying.
