pymongo


backup collection using pymongo


since eval() and copyTo() have been deprecated from mongodb3+. I'm looking at a way to take a back up of collection using something like
db.collection.find().forEach(function(d){db.collection_backup.save(d)})
I'm basically looking for help on these two.
1: How do I run any .js file on Mongo with PyMongo. Example:
mongo < something.js and the js file can have some specific set of commands or functions.
2: how do I run my above code to take the backup of collections across 100s' of databases using pymongo
Thanks in advance for the help.
PyMongo does not include a feature for executing a .js file on the server.
An aggregation pipeline with $out is an efficient way to copy a collection. If you want to back up the "role" collection, for example, in each database:
from pymongo import MongoClient
client = MongoClient()
for db_name in client.database_names():
db = client[db_name]
if 'role' in db.collection_names():
print('copy %s.role' % db_name)
db.role.aggregate([{'$match': {}}, {'$out': 'role_backup'}])

Related Links

how to find right version of bson from pip for pymongo/mongoengine
How to enable `projection` in pymongo query class `find()`?
Variables don't hold value for very long pymongo ipython
pymongo upgrade to 3.0.3 causes this statement to fail
UUID to NUUID in Python
how to test for empty mongodb query in pymong
read video file from mongodb with pymongo
Get OperationFailure error with PyMongo 2.7.1
Inserting string as regular string in mongodb
Mongos + Pymongo 2.5 ==>No suitable hosts found
pymongo collection add item using update
How to convert objectid to string
Conditional atomic mongo remove with different results
python script to connect to mongodb master
flask-admin and pymongo search
Running code when mongoengine loads a document

Categories

HOME
ionic2
protocol-buffers
freeradius
writefile
systemd
ios-simulator
odata
websocket
dronekit-python
biztalk-2010
flurry
openfoam
facebook-android-sdk
javafx-8
elastic-load-balancer
amazon-emr
circleci
fullcalendar-scheduler
dma
sonicwall
vmware-workstation
user-defined-types
boomi
adminlte
social-tables
gitkraken
kaggle
stackexchange.redis
netbios
delayed-job
mongoengine
xmlunit
image-optimization
jfxtras
variable-variables
imgur
slideshow
angular-datatables
hypothesis-test
coverage.py
dagger
httphandler
julius-speech
sendinput
nomad
linq-to-excel
realstudio
django-static-precompiler
icecast
md5-file
head.js
http-basic-authentication
rcharts
zend-server
front-camera
streamwriter
nclam
pyaudio
right-to-left
node.js-connect
unsigned
adp
apple-configurator
gulp-uglify
gwt-syncproxy
vim-plugin
place
jnlp
libz
fantom
algebraixlib
ocmockito
nssortdescriptor
dos2unix
dc
igor
ecos
category-theory
distributed-r
prism.js
senchatouch-2.4
bittorrent-sync
jack
code39
rikulo
oscilloscope
semantic-merge
live-wallpaper
gamesalad
prototypal-inheritance
mmc3
dynamic-c
will-paginate
delphi-prism
snackjs
fork-join
downgrade
sscli
ixmldomdocument
levels
synthesizer

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App