A similar situation arises in The Arsenal of Freedom. Geordi is put in command while Picard and Riker are on the planet. Chief Engineer Logan tries to pull rank and assume command, but Geordi basically tells him to eff off.
Indeed, Starfleet seems to put a lot of store by position, and rank seems to actually have very little relevance at all.
This is especially true in Voyager, where Ensign Harry Kim is treated as far more senior than dozens of Lt. Cmdr. ranks walking around the ship. I always found that a bit daft.
Also equally silly seems the fact every commander of a ship, no matter what size or capability, holds the rank of full Captain. In the real military the idea that the commander of a Minesweeper would hold a higher rank than the XO of an aircraft carrier would be mental. One commands 20 guys, one essentially commands 5,000.
It does make some in-universe sense though. Starfleet seems to have a relaxed approach to rank compared to a modern military as suits its sometimes quasi-military portrayal. Terefore Data deferring to Geordi in Engineering is as much about Geordi knowing his stuff and Data's respect for that as it is about Geordi's actual position.
In a crunch, where they disagree, Data's rank would give him the call, but when there is no crunch - it is likely they would all sit and have a meeting, as they regularly did in TNG.
These answers are sort of contradictory. If Data's rank allows him to 'make the call' in crunch situations, then why didn't Logan's rank allow him to make the call when Picard and Riker were on the planet?
It's best to ignore rank. Position matters a lot more than rank.
In that episode Geordi was in the POSITION of commanding the ship. He was in charge no matter what Logan thought or the ranked-captains on the ship thought. Geordi may not have been a captain but for all intents and purposes he was Captain. (Note capitalization.)
Geordi is in command of the Engineering section, he's in charge of everyone there even those who out-rank him. But he has to act, and answer to, Picard, Riker and Data who are commanding officers. Data's the Operations Officer so I take that to mean he's the superior of all of the "operations" departments, essentially anyone in a gold uniform who're tasked with operating the ship. The "working relationship" Data and Geordi built, however, was more of a mutual one rather than a commander/subordinate one.
In "theory" Data should have some authority over Geordi since Data is the Operations Manager and third in command. (Geordi not being in the command chain.)
This is an in-ideal way of looking at it, but it's how I think how it more-or-less works when everyone is on the ship and doing their job. Their things change, obviously, when Picard and Riker or are not in the ship and, say, leave Data in charge. Or when Data has the watch, what have-you.
But "ideally" this is how it works.
I'm not entirely sure if Troi would be considered part of the "medical staff" or just simply the head of the counseling "department" answering to no one but Picard/Riker/Data and not necessarily to the CMO/Crusher.
But, "realistically" how it'd work is like this. Say someone in Engineering wants something. A raise, more vacation time, whatever. He goes to Geordi and asks for it. Geordi then tells Data this, since Data is the head of Operations and Engineering is an operations department, and then Data tells Riker who tells Picard. Now, sure, we know the crew is a bit less formal in many regards and Geordi likely would have gone straight to Riker or even Picard but under a strict, we'll say, "Jelico-ian" rule this is how it should work. We see this happen, in fact, when Jelico is in command. People start complaining about the new duty schedule, the department heads tell Riker who tells Jelico.
There are, in deed, some muddy areas. Data is third in command of the ship and, thus, likely has command over everyone Riker is in charge of as well as his own departments but in normal operations he likely doesn't exert this unless someone is working directly for him.