Skip to content

Tag: mongodb

MongoDB/Python – Date in collection (to use for query)

I just started using mongoDB (Version 3.6.8) today, and I like it. I was reading that it should be possible to have a date object directly in the database, but I can’t get it to work. Also I was wondering if it is the best solution or if I should just store my dates as “Epoch millis” instead…

How to get keys of nested mongodb documents

I have data like this, I need all the keys from this mongodb collection like property1,property2 etc. I tried Answer You can use $objectToArray to read object keys dynamically and then run $reduce with $concatArrays to merge the results: Output: Mongo playground

How to import JSON file to MongoDB using Python

I have this JSON file, currencies.json: And this connection in Python: My db name is countries_db with the currency collection. Is there a way to import the file to the db using python? Thanks for your help. Answer You can read data from file and insert it into collection using insert_one method:

pymongo auth failed in python script

I have installed mongodb and enabled auth. and its working find. I can connect it from remote notebook using robomongo application: and We can connect from server shell locally using: Everything works fine, but when we try it using pymongo api. authentications failed. below is the python code: Tools used: Err…

get mongodb “_id” in django template

My question is related to this question. I am trying to display all the _id of mongo database in django template from last 2 days but unable to get it. This is the error: This is the code I am trying: views.py product.html Though, I tried changing the name to static, cache etc, but still no luck. Answer templ…

How to run MongoDB commands with pymongo?

I need to see list of connections to MongodDB. I know how to do it in mongo console: Now I want to do the same using pymongo. I tried following and it didn’t work: After that I used db.command() in various combinations trying to pass “db.currentOp(true)” to it without success. How to do it p…