Using the mongo shell which is javascript:
db.collection.insert()
Can I allow the collections name to be dynamic so as to work with several collections?
From the mongo shell:
You can create variable using var for collection name
var colName = "mytest"
and then execute all the operations on collections as below:
db[colName].find()
db[colName].rename("newName")
etc. This will help you keep your collection name dynamic and can even update it keeping your commands same.
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With