<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 2.3 Integration with MongoDB databases
Instead of storing the index in a variable or in a plain-text file, we could export it to any tool of our choice.
For convenience, signac provides export routines for MongoDB database collections.
Please note
Step1:  We can export either the project index directly via
Step2:  Or we compile and export a master index
Step3:  In both cases we can now use MongoDB's query engine for advanced search queries.
For example, let's find the mean gas volume of water for the pressure range (2.0 < p <= 5.0)
<ASSISTANT_TASK:>
Python Code:
import signac
#
# --- PLEASE UNCOMMENT ONE OF THE FOLLOWING TWO CONFIGURATIONS ---
#
# --- 1) USING A LOCAL MONGODB INSTANCE ---
#from pymongo import MongoClient
#client = MongoClient()
#db = client.testing
# --- 2) USING A SIGNAC DATABASE CONFIGURATION ---
db = signac.get_database('testing')
index = db.signac_tutorial_index
index.drop()
master_index = db.signac_tutorial_master_index
master_index.drop()
Explanation: 2.3 Integration with MongoDB databases
Instead of storing the index in a variable or in a plain-text file, we could export it to any tool of our choice.
For convenience, signac provides export routines for MongoDB database collections.
Please note: The following steps require pymongo and either a local MongoDB instance or a signac database configuration.
End of explanation
project = signac.get_project(root='projects/tutorial')
signac.export(project.index(), index)
Explanation: We can export either the project index directly via:
End of explanation
signac.export(signac.index(), master_index, update=True)
Explanation: Or we compile and export a master index:
End of explanation
import numpy as np
query = {
    '$and': [{'statepoint.p': {'$gt': 2.0}}, {'statepoint.p': {'$lte': 5.0}}],
    'fluid': 'water',
    'V_gas': {'$exists': True}}
docs = master_index.find(query)
V = np.array([doc['V_gas'] for doc in docs])
print(V.mean())
Explanation: In both cases we can now use MongoDB's query engine for advanced search queries.
For example, let's find the mean gas volume of water for the pressure range (2.0 < p <= 5.0):
End of explanation
<END_TASK>