Question

I'm trying to install this software, a few scripts for searching in a local mongodb database: https://github.com/wimremes/cve-search/blob/master/README.md

Since the search.py script fail miserably, I'm trying to put some index as suggested:

db.cpe.ensureIndex( {id:1 } )
db.cves.ensureIndex( {id:1} )
db.cves.ensureIndex( {vulnerable_configuration:1} )
db.vfeed.ensureIndex( {id:1} )

But this code is not working: ensureIndex fail with this error:

File "build/bdist.linux-i686/egg/pymongo/collection.py", line 1672, in __call__
TypeError: 'Collection' object is not callable. If you meant to call the 'ensureIndex' method on a 'Collection' object it is failing because no such method exists.

and ensure_index( {id:1}) return this:

TypeError: if no direction is specified, key_or_list must be an instance of list

What shoud I do for ceating new indexes?

Was it helpful?

Solution 2

What you've written is in Javascript syntax. In Python using PyMongo, the same operations look like:

db.cpe.ensure_index( {'id':1 } )
db.cves.ensure_index( {'id':1} )
db.cves.ensure_index( {'vulnerable_configuration':1} )
db.vfeed.ensure_index( {'id':1} )

OTHER TIPS

Actually, in PyMongo they would look like this:

db.collection.ensure_index([("id", pymongo.ASCENDING)])

You can read more in the PyMongo Documentation.


Update: In version 3.0 and above ensure_index has been removed. You should now use create_index instead. For more info, see the docs for the JavaScript library.

You can also read about ensure_index vs create_index here: Pymongo / MongoDB: create index or ensure index?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top