icoz / pysymo

syslog-ng mongodb analyzer
GNU General Public License v2.0
1 stars 2 forks source link

Fixed to run with latest flask and py-mongo #3

Closed feldsam closed 8 years ago

feldsam commented 8 years ago

Signed-off-by: Kristián Feldsam feldsam@gmail.com

ilya-il commented 8 years ago

feldsam, what version of pymongo do you use? I can't manage to work your code in 'refresh_charts.py':

-    for i in list(res):
+    for i in list(res['result']):
Traceback (most recent call last):
  File "./refresh_charts2.py", line 179, in <module>
    main()
  File "./refresh_charts2.py", line 175, in main
    top_hosts()
  File "./refresh_charts2.py", line 33, in top_hosts
    for i in res['result']:
TypeError: 'CommandCursor' object has no attribute '__getitem__'

I've tested it with pymongo 3.1.1 and 3.3.0

feldsam commented 8 years ago

Hello, I just installed using pip install -r requirements_py2.txt

Metadata-Version: 1.1
Name: pymongo
Version: 2.5.2
Summary: Python driver for MongoDB <http://www.mongodb.org>
Home-page: http://github.com/mongodb/mongo-python-driver
Author: Bernie Hackett
Author-email: bernie@10gen.com
License: Apache License, Version 2.0
Location: /usr/lib64/python2.7/site-packages
Requires:

Probably, best will will be add package version to requirements.txt file....

ilya-il commented 8 years ago

According to pymongo 2.5.2 docs some things are changed:

  1. There is no update_one() in 2.5.2, only update(): http://api.mongodb.com/python/2.5.2/api/pymongo/collection.html#pymongo.collection.Collection.update
  2. Aggregation method returns list and you we should use my_aggr['result'] http://api.mongodb.com/python/2.5.2/examples/aggregation.html

In pymongo >= 3 we see this:

  1. update() method is deprecated
  2. Aggregation returns CommandCursor, that can be iterated as list

http://api.mongodb.com/python/current/api/pymongo/collection.html

update(spec, document, upsert=False, manipulate=False, multi=False, check_keys=True, **kwargs)

Update a document(s) in this collection.

DEPRECATED - Use replace_one(), update_one(), or update_many() instead.

Changed in version 3.0: Removed the safe parameter. Pass w=0 for unacknowledged write operations.

http://api.mongodb.com/python/current/api/pymongo/command_cursor.html

So I'll revert your changes for refresh scripts and update requirements to match modern versions.

feldsam commented 8 years ago

Oh, sorry, You should also check Flask. I dont't know if latrest version installed or not. I just run that pip and decide that it install latest packeges and app was broken due to missing package versions defined......

ilya-il commented 8 years ago

What OS do you use? Flask imports is ok for now.

feldsam commented 8 years ago

CentOS Linux release 7.2.1511 (Core) Linux backup.feldhost.cz 3.10.0-327.28.3.el7.x86_64 #1 SMP Thu Aug 18 19:05:49 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux