mongodb_store.message_store module

class mongodb_store.message_store.MessageStoreProxy(service_prefix='/message_store', database='message_store', collection='message_store', queue_size=100)[source]

A class that provides functions for storage and retrieval of ROS Message objects in the mongodb_store. This is achieved by acting as a proxy to the services provided by the MessageStore ROS node, and therefore requires the message store node to be running in addition to the datacentre:

rosrun mongodb_store message_store_node.py

>>> from geometry_msgs.msg import Pose, Quaternion
>>> msg_store = MessageStoreProxy()
>>> p = Pose(Point(0, 1, 2), Quaternion(0, 0, 0 , 1))
>>> msg_store.insert_named("my favourite pose", p)
>>> retrieved = msg_store.query_named("my favourite pose", Pose._type)

For usage examples, please see example_message_store_client.py within the scripts folder of mongodb_store.

__init__(service_prefix='/message_store', database='message_store', collection='message_store', queue_size=100)[source]
Args:
service_prefix (str): The prefix to the insert, update, delete and query_messages ROS services/
database (str): The MongoDB database that this object works with.
collection (str): The MongoDB collection that this object works with.
delete(message_id)[source]

Delete the message with the given ID.

Parameters:
message_id (str) : The ObjectID of the MongoDB document holding the message.
Returns:
bool : was the object successfully deleted.
insert(message, meta={}, wait=True)[source]

Inserts a ROS message into the message storage.

Args:
message (ROS Message): An instance of a ROS message type to store
meta (dict): A dictionary of additional meta data to store in association with thie message.
wait (bool): If true, waits until database returns object id after insert
Returns:
(str) the ObjectId of the MongoDB document containing the stored message.
insert_named(name, message, meta={}, wait=True)[source]

Inserts a ROS message into the message storage, giving it a name for convenient later retrieval. .. note:: Multiple messages can be stored with the same name.

Args:
name (str): The name to refere to this message as.
message (ROS Message): An instance of a ROS message type to store
meta (dict): A dictionary of additional meta data to store in association with thie message.
wait (bool): If true, waits until database returns object id after insert
Returns:
(str) the ObjectId of the MongoDB document containing the stored message.
query(type, message_query={}, meta_query={}, single=False, sort_query=[], projection_query={}, limit=0)[source]

Finds and returns message(s) matching the message and meta data queries.

Parameters:
type (str): The ROS message type of the stored messsage to retrieve.
message_query (dict): A query to match the actual ROS message
meta_query (dict): A query to match against the meta data of the message
sort_query (list of tuple): A query to request sorted list to mongodb module
projection_query (dict): A query to request desired fields to be returned or excluded
single (bool): Should only one message be returned?
limit (int): Limit number of return documents
Returns:
[message, meta] where message is the queried message and meta a dictionary of meta information. If single is false returns a list of these lists.
query_id(id, type)[source]

Finds and returns the message with the given ID.

Parameters:
id (str): The ObjectID of the MongoDB document holding the message.
type (str): The ROS message type of the stored messsage to retrieve.
Returns:
message (ROS message), meta (dict): The retrieved message and associated metadata or None if the named message could not be found.
query_named(name, type, single=True, meta={}, limit=0)[source]

Finds and returns the message(s) with the given name.

Args:
name (str): The name of the stored messages to retrieve.
type (str): The type of the stored message.
single (bool): Should only one message be returned?
meta (dict): Extra queries on the meta data of the message.
limit (int): Limit number of return documents
Return:
message (ROS message), meta (dict): The retrieved message and associated metadata or None if the named message could not be found.
update(message, meta={}, message_query={}, meta_query={}, upsert=False)[source]

Updates a message.

Args:
message (ROS Message): The updated ROS message
meta (dict): Updated meta data to store with the message.
message_query (dict): A query to match the ROS message that is to be updated.
meta_query (dict): A query to match against the meta data of the message to be updated
upsert (bool): If True, insert the named message if it doesnt exist.
Return:
str, bool: The MongoDB ObjectID of the document, and whether it was altered by the update.
update_id(id, message, meta={}, upsert=False)[source]

Updates a message by MongoDB ObjectId.

Args:
id (str): The MongoDB ObjectId of the doucment storing the message.
message (ROS Message): The updated ROS message
meta (dict): Updated meta data to store with the message.
upsert (bool): If True, insert the named message if it doesnt exist.
Return:
str, bool: The MongoDB ObjectID of the document, and whether it was altered by the update.
update_named(name, message, meta={}, upsert=False)[source]

Updates a named message.

Args:
name (str): The name of the stored messages to update.
message (ROS Message): The updated ROS message
meta (dict): Updated meta data to store with the message.
upsert (bool): If True, insert the named message if it doesnt exist.
Return:
str, bool: The MongoDB ObjectID of the document, and whether it was altered by the update.