I have someone's code who is not in the company and I want to get the data stored in mongo database which is using AsyncIOMotorClient. I have no experience with motor.
Problem:
I am able to get this:
AsyncIOMotorCursor(<pymongo.cursor.Cursor object at 0x7fbd87b45ca0>)
I know how to iterate over <pymongo.cursor.Cursor object at 0x7fbd87b45ca0>, but when I try to iterate over the above AsyncIOMotorCursor, I get the following error:
TypeError: 'AsyncIOMotorCursor' object is not iterable
Kindly help.
Related
Problem: I want to pick a field of index in elasticsearch and look for all the values against it. Like if I give a key I should get the value for that key and if that key exists more than once, so each whats the each value. Or even if I get one of the values would work for me.
How I am trying to work through it: Query the elasticsearch
I am trying to query my data from Elasticsearch;
r = es.search(index="test",body = {'query': {'wildcard': {'task_name': "*"}}})
I thought to load the data to a python object ( dictionary) to read a key values. However, when I try json.loads(r.json) it gives me an error : AttributeError: 'dict' object has no attribute 'json'.
I even tried with json.load(r) but the error remains the same.
for example lets say
books.objects.raw(....)
the (...) are a representation of the sql parameters for example as seen in the django docs
https://docs.djangoproject.com/en/3.2/topics/db/sql/#:~:text=Django%20gives%20you%20two%20ways,ORM%20before%20using%20raw%20SQL!
when i try to iterate through the above oject like so
[print(x) for x in books.ojects.raw(...)]
I get this from my logs below
django.db.utils.ProgrammingError: can't adapt type 'dict'
I am trying to use elastic search libraries like pyelasticsearch and elasticsearch I am not getting any method where i can pass dataframe and that method will load data frame data to elastic search.
I am trying a this code:
for i,df in enumerate(csvfile):
print (i)
records=df.where(pd.notnull(df), None).T.to_dict()
list_records=[records[it] for it in records]
print(list_records)
try :
es.bulk_index("call_demo_data1","tweet",list_records)
except :
print ("error!, skiping some tweets sorry")
pass
where csvfile is my dataframe where my all data is present. but I am getting following error
'str' object has no attribute 'where'
I have used recommendation in comments
Now that problem is solved I am getting this error while bulk loading
I am using above method to load data elastic search I was facing problem so here is the link to the question I posted earlier
Here is the code I am using now :
records= csvfile.T.to_dict()
list_records=[records[it] for it in records]
#print(list_records)
es.bulk_index("call_demo_data1","tweet",list_records)
Error I am getting is :
too many values to unpack (expected 2)
this error is coming while bulk indexing. csvfile in above code is a data frame. I am using this liabrary pyelasticsearch
This is the error traceback
I was wondering if I could get some help on an error I have with an app I am making with Flask-sqlalchemy and a postgres database. I currently have a list of years (ints). the elements of the list depend on the year that the user selects. With the list I make a query below searching for results in my database that have fiscal years matching the years in my list:
#main.route('/searchresults')
def yearresults():
entries = db.session.query(Post).filter(Post.fiscalyear.in_(list))
return render_template('yearsearch.html', entries=entries)
When I run this, however, I get
TypeError: 'type' object is not iterable
The error occurs on the line of the query (db.session.query(Post).filter...)
I know my code works when I query with one specific year, but I'm trying to get it to work with multiple unknowns. I was wondering if anyone sees a solution or a better way to do this.
Thanks in advance!
list in your code is a Python built-in object list (type).
Please provide actual list object there.
I have a value in orientdb, which is a JSON object.
Assume that JSON object is :
a = {"abc":123}
When I am sending a query using pyorient, it is not able to get this value in the select query, and hangs.
In the orientdb console, this JSON object seems to be converted in some other format like
a = {abc=123}
I guess it is hanging because of the same issue.
The query from pyorient is:
client.query("select a from <tablename>")
This hangs and doesn't seems to be working.
Could you please help ho to parse this JSON object in pyorient?
I used OrientDb's REST API service to fetch JSON object fields from the database. PyOrient hangs when requested for a JSON object field.
So fetch the rid of the record you want, and use REST services to get all the fields, which worked perfectly fine.
pyorient gives you the output something like:
a = {'abc': '123'}
and json.loads() function works with " and not with ', so to solve it, you need to do this:
b=str(a)
b.replace("'",'"')
json_data = json.loads(b)
print(json_data.keys())
I have defined a function to get vertex and after you get your vertex you can use for loop to parse the json result. Lets say the vertex "Root" have an attribute "name", and in the for loop after the query execution we can parse the value like "res.name" to fetch the value.
I think in recent version, they fixed the hanging issue. I am not facing any issue with hanging while query execution.
def get_verted(vertex):
result = client.command("select * from "+vertex)
for res in result:
print res.name
get_vertex("Root")