How to search all the collections of a database-name: test
for a word having length
say 6
The sample data in collections is like:
{
"_id": {
"$oid": "5e0983863bcf0dab51f2872b"
},
"word": "never",
"wordset_id": "a42b50e85e",
"meanings": [{
"id": "1f1bca9d9f",
"def": "not ever",
"speech_part": "adverb",
"synonyms": ["ne'er"]
}, {
"id": "d35f973ed0",
"def": "not at all",
"speech_part": "adverb"
}]
}
How can I query for all words with length
of 6
across all collections of test
?
I have tried this way but it is giving only first collection results:
@app.......
def fn():
collections=db.collection_names()
for collection in collections:
data = db[collection].aggregate([
{
"$match": {
"$expr": {"$eq": [{"$strLenCP": "$word"}, n]}
}
}
])
return render_template('lettersearch.html',data=data)
when I am printing data I get all cursors as:
<pymongo.command_cursor.CommandCursor object at 0x00000258F4F5B470>
<pymongo.command_cursor.CommandCursor object at 0x00000258F4F76BA8>
<pymongo.command_cursor.CommandCursor object at 0x00000258F4F6E5F8>
<pymongo.command_cursor.CommandCursor object at 0x00000258F4F8A6A0>
<pymongo.command_cursor.CommandCursor object at 0x00000258F4F8E048>
How to iterate over these objects and render in template as data
?