From 5a67ce3d2d5ff0f4b6a582fd09585b457881bbb1 Mon Sep 17 00:00:00 2001 From: cedricbonhomme Date: Mon, 22 Oct 2012 08:44:09 +0200 Subject: Minor improvements for the management of the database. --- source/mongodb.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'source/mongodb.py') diff --git a/source/mongodb.py b/source/mongodb.py index 95d7560c..e83b7324 100644 --- a/source/mongodb.py +++ b/source/mongodb.py @@ -37,8 +37,9 @@ class Articles(object): """ Instantiates the connection. """ + self.db_name = db_name self.connection = pymongo.connection.Connection(url, port) - self.db = pymongo.database.Database(self.connection, db_name) + self.db = pymongo.database.Database(self.connection, self.db_name) self.db.authenticate(user, password) def add_collection(self, new_collection): @@ -81,6 +82,7 @@ class Articles(object): def get_all_feeds(self, condition=None): """ + Return all feeds object. """ feeds = [] collections = self.db.collection_names() @@ -97,13 +99,14 @@ class Articles(object): def get_all_articles(self): """ - Return all articles from all collections. + Return articles of all feeds object (articles of all MongoDB articles collections). + All articles collections are of type 1. """ articles = [] collections = self.db.collection_names() for collection_name in collections: collection = self.db[collection_name] - articles.extend([article for article in collection.find({'type':1})]) + articles.extend(collection.find({'type':1})) return articles def get_article(self, feed_id, article_id): @@ -227,11 +230,11 @@ class Articles(object): return collections # Functions on database - def drop_database(self, db_name="pyaggr3g470r"): + def drop_database(self): """ Drop all the database """ - self.connection.drop_database(db_name) + self.connection.drop_database(self.db_name) if __name__ == "__main__": -- cgit