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

python motor mongo cursor length or peek next
PyMongo check if update succeeded
insert and query an OrderedDict in MongoHQ
Return .str of ObjectID using pymongo
Selecting the lowest/highest with find_one in Pymongo
Safe use of Pymongo's find_one
Pymongo $in + $regex
How can I get pymongo to always return str and not unicode?
SON Manipulator in mongo queries
How to append a document to a 2nd level embedded model list document in Django and mongoengine
pymongo multiple update $in
How to get negetive of a complex where clause in mongo db
pymongo justOne & multi
How to make pymongo's find() return a list?
convert pymongo cursor to json
How to do query on pymongo and get values in the reverse order of inserting

Categories

HOME
firebase
freeradius
windows-8.1
systemd
risk-management
biztalk-2010
repair
polymer-2.x
hystrix
lc3
fireloop
sap-fiori
sonata
trace32
reselect
android-contacts
multiple-tables
pfobject
prompt
spreadsheetgear
hevc
gravity-forms-plugin
premake
rust-cargo
om-next
apptentive
spring-rabbitmq
pdfnet
jade4j
cargo
unification
grunt-contrib-watch
suds
word-cloud
sendinput
apache-modules
gapi
yui3
multi-touch
pjax
decoder
system.net.mail
bbc-micro
unsigned
adp
android-syncadapter
rails-engines
frame-grab
jsr363
gdl
json-spirit
ibm-was
mixins
erlog
prism-4
python-curses
thoughtworks-go
adwords-apiv201402
window-resize
igor
quantify
full-text-indexing
air-native-extension
gpu-programming
jms-serializer
pbkdf2
ggts
grails-2.3
san
sql-view
insertonsubmit
oembed
email-verification
taskkill
autosize
memory-pool
drawimage
boost-foreach
vows
office-automation
tablet-pc
resharper-5.1
principles
aspbutton
dm
main-method

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App