As with the visiting officers, I noticed that Cmder Shelby had the same rank as Data, but she was giving Data orders even though he's the ship second officer.
Shelby wore the red uniform that kind of suggested she had automatic authority or something.
Again it is her position, not rank. She was essentially inserted into the command crew by Hansen, and seems to report directly to Riker.
That said, it never comes to a crunch during the episode, it is quite likely Data would have listened to an Ensign Shelby at that point, nothing to lose!