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:


Syntax

For javascript indexes, use the method Cmpxchg(<key>).
Parameter Type Description
key string The key of a particular compare exchange value.


Examples

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

class Compare_Exchange_Index extends AbstractIndexCreationTask {
    constructor() {
        super();

        this.map = `docs.HotelRooms.Select(room => new { 
                         RoomID = room.RoomID,     
                         Guests = cmpxchg(room.RoomID)
             })`;
    }
}

Querying the Index

const VIPRooms = await session
    .advanced.rawQuery<HotelRoom>(
    "   from Hotelrooms as room\n"+
    "   where room.Guests == cmpxchg('VIP')"
)