I am trying to insert BTC blocks and transactions in MONGODB collection from count 0 using Python3.
getrawtransaction is giving output for block 1 but not for block 0. Can somebody help me why this happening?
It's a result of a quirk from the original Bitcoin client which has been carried forward to today. Originally, the UTXO database held entire transactions; it was similar to/basically the same as the transaction index that exists now today. However the original Bitcoin client had a bug where it did not include the transaction data of the genesis block. This is because the genesis block was not processed like every new block so it's data never made it into the UTXO database. Because it was never part of the UTXO database, it affects consensus so this bug cannot be fixed without a hard fork.
Fast forward to today and the genesis block is still not processed like other blocks in order to keep UTXO databases consistent so there is not a hard fork. This also means that the transaction in the genesis block won't be part of any databases, including the transaction index, which is why you cannot look up that transaction. Fixing this so that the transaction were added to the transaction index would require significant changes to fix this one special case as the block cannot be processed or it may cause a hard fork.
Instead of trying to query the transaction, you should use
getblock using verbosity level 2. This will decode the block even further to give you the transactions decoded instead of just their transaction ids. Since the block itself is known and in the block index, the block can be fetched and decoded so yo ucan get the transaction data that way. In fact, I would recommend that you always use
getblock with verbosity 2 so you can get the block data and all of the transaction data decoded with one RPC instead of needing multiple to fetch each transaction in a block.