#include <message_collection.h>
Public Member Functions | |
unsigned | count () |
Count messages in collection. | |
MessageCollection & | ensureIndex (const std::string &field) |
MessageWithMetadata< M >::ConstPtr | findOne (const Query &query, bool metadata_only=false) const |
Convenience function that returns a single matching result for the query. | |
void | insert (const M &msg, const Metadata &metadata=Metadata()) |
Insert a ROS message, together with some optional metadata, into the db. | |
MessageCollection (const std::string &db_name, const std::string &collection_name, const std::string &db_host="", unsigned db_port=0, float timeout=300.0) | |
Will connect to given database and collection. Collection is created if it doesn't exist. | |
void | modifyMetadata (const Query &q, const Metadata &m) |
Modify metadata Find message matching q and update its metadata using m In other words, overwrite keys in the message using m, but keep keys that don't occur in m. | |
std::vector< typename MessageWithMetadata< M > ::ConstPtr > | pullAllResults (const mongo::Query &query, bool metadata_only=false, const std::string &sort_by="", bool ascending=true) const |
Convenience function that calls queryResult and puts the results into a vector. | |
QueryResults< M >::range_t | queryResults (const mongo::Query &query, bool metadata_only=false, const std::string &sort_by="", bool ascending=true) const |
unsigned | removeMessages (const mongo::Query &query) |
Remove messages matching query. | |
Private Member Functions | |
void | initialize (const std::string &db, const std::string &coll, const std::string &host, unsigned port, float timeout) |
Private Attributes | |
boost::shared_ptr < mongo::DBClientConnection > | conn_ |
boost::shared_ptr< mongo::GridFS > | gfs_ |
ros::Publisher | insertion_pub_ |
ros::NodeHandle | nh_ |
const std::string | ns_ |
Represents a collection of ROS Messages stored in a MongoDB database. Each stored message in the db has a unique id, a creation time, and optional additional metadata stored as a dictionary
Definition at line 52 of file message_collection.h.
mongo_ros::MessageCollection< M >::MessageCollection | ( | const std::string & | db_name, |
const std::string & | collection_name, | ||
const std::string & | db_host = "" , |
||
unsigned | db_port = 0 , |
||
float | timeout = 300.0 |
||
) |
Will connect to given database and collection. Collection is created if it doesn't exist.
db_host | If provided, will be used instead of looking up the warehouse_host ros parameter. |
db_port | If provided, will be used instead of looking up the warehouse_port ros parameter. |
timeout | Throw a DbConnectException if can't connect within this many seconds |
Definition at line 56 of file message_collection_impl.h.
unsigned mongo_ros::MessageCollection< M >::count | ( | ) |
Count messages in collection.
Definition at line 231 of file message_collection_impl.h.
MessageCollection< M > & mongo_ros::MessageCollection< M >::ensureIndex | ( | const std::string & | field | ) |
Definition at line 107 of file message_collection_impl.h.
MessageWithMetadata< M >::ConstPtr mongo_ros::MessageCollection< M >::findOne | ( | const Query & | query, |
bool | metadata_only = false |
||
) | const |
Convenience function that returns a single matching result for the query.
NoMatchingMessageException |
Definition at line 180 of file message_collection_impl.h.
void mongo_ros::MessageCollection< M >::initialize | ( | const std::string & | db, |
const std::string & | coll, | ||
const std::string & | host, | ||
unsigned | port, | ||
float | timeout | ||
) | [private] |
Definition at line 69 of file message_collection_impl.h.
void mongo_ros::MessageCollection< M >::insert | ( | const M & | msg, |
const Metadata & | metadata = Metadata() |
||
) |
Insert a ROS message, together with some optional metadata, into the db.
mongo::DBException | if unable to insert |
metadata | Metadata to insert. Note that a unique id field _id and a field creation_time will be autogenerated for all messages. |
As a secondary effect, publishes a notification message on the topic warehouse/db/collection/inserts
Get the BSON and id from the metadata
Serialize the message into a buffer
Definition at line 115 of file message_collection_impl.h.
void mongo_ros::MessageCollection< M >::modifyMetadata | ( | const Query & | q, |
const Metadata & | m | ||
) |
Modify metadata Find message matching q and update its metadata using m In other words, overwrite keys in the message using m, but keep keys that don't occur in m.
Definition at line 210 of file message_collection_impl.h.
vector< typename MessageWithMetadata< M >::ConstPtr > mongo_ros::MessageCollection< M >::pullAllResults | ( | const mongo::Query & | query, |
bool | metadata_only = false , |
||
const std::string & | sort_by = "" , |
||
bool | ascending = true |
||
) | const |
Convenience function that calls queryResult and puts the results into a vector.
Definition at line 166 of file message_collection_impl.h.
QueryResults< M >::range_t mongo_ros::MessageCollection< M >::queryResults | ( | const mongo::Query & | query, |
bool | metadata_only = false , |
||
const std::string & | sort_by = "" , |
||
bool | ascending = true |
||
) | const |
Iterator | range over matching messages |
query | A metadata object representing a query. |
metadata_only | If this is true, only retrieve the metadata (returned message objects will just be default constructed) |
Definition at line 150 of file message_collection_impl.h.
unsigned mongo_ros::MessageCollection< M >::removeMessages | ( | const mongo::Query & | query | ) |
Remove messages matching query.
Definition at line 190 of file message_collection_impl.h.
boost::shared_ptr<mongo::DBClientConnection> mongo_ros::MessageCollection< M >::conn_ [private] |
Definition at line 125 of file message_collection.h.
boost::shared_ptr<mongo::GridFS> mongo_ros::MessageCollection< M >::gfs_ [private] |
Definition at line 126 of file message_collection.h.
ros::Publisher mongo_ros::MessageCollection< M >::insertion_pub_ [private] |
Definition at line 128 of file message_collection.h.
ros::NodeHandle mongo_ros::MessageCollection< M >::nh_ [private] |
Definition at line 127 of file message_collection.h.
const std::string mongo_ros::MessageCollection< M >::ns_ [private] |
Definition at line 124 of file message_collection.h.