The 2 dimensions listed for each shock are;
- The eye to eye length (sometimes listed as i2i, this is the distance between the 2 mounting points)
- The shock stroke, i.e. how far the the shock shaft will move
If the two shocks have the same eye to eye length and the same stroke then the Monarch will physically fit into the frame and allow full travel without fouling the frame (See note below).
The other thing to consider is the damping tune of the shock. Shock manufactures produce a variety of shock tunes to suit different suspension designs (and a large company like Trek might even commission custom tunes). While this will not stop a shock from working in a frame it may result in undesirable handling. Typically the damping tune of a shock can be altered during a service (full service not air can service).
In your case I would expect that the Monarch will be just fine. Be careful to check the clearances before riding.
Note: some shocks are wider or have a piggy back reservoirs. Care should be taken to make sure the new shock does not foul the frame at any point during its travel. Typically you would do this by removing all air from the shock and cycling the suspension by hand and checking the clearances.