Indexes: Indexing Compare Exchange Values

  • Compare exchange values can be loaded within an index using the value's key.

  • The index will update when the compare exchange value is updated, as well as when documents are modified in the indexed collection(s).

  • In this page:

How to use

When creating an index using AbstractIndexCreationTask, use javaScript to load a compare exchange value by its key.


These indexes map the rooms in a hotel, as well as compare exchange values representing the guests in those rooms.

private class Compare_Exchange_JS_Index extends AbstractJavaScriptIndexCreationTask{
    public Compare_Exchange_JS_Index()
                "map('HotelRooms', function (room) {\n"+
                "   var guests = cmpxchg(room.RoomID);\n"+
                "   return {\n"+
                "       RoomID: room.RoomID,\n"+
                "       Guests: guests\n"+
                "   }\n"+

Querying the Index

IRawDocumentQuery<Hotelroom> VIPRooms = session.advanced().rawQuery(Hotelroom.class,
    "from Hotelrooms as room\n" +
        "where room.Guests == cmpxchg('VIP')");