stop mongodb creating dbs and collections dynamically

前端 未结 3 1792
南方客
南方客 2021-01-11 10:58

Is there a way to switch off the ability of mongo to sporadically create dbs and collections as soon as it sees one in a query. I run queries on the mongo console all the ti

3条回答
  •  悲哀的现实
    2021-01-11 11:18

    To be clear, MongoDB does not auto create collections or databases on queries. For collections, they are auto created when you actually save data to them. You can test this yourself, run a query on a previously unknown collection in a database like this:

    use unknowndb
    db.unknowncollection.find()
    show collections
    

    No collection named "unknowncollection" shows up until you insert or save into it.

    Databases are a bit more complex. A simple "use unknowndb" will not auto create the database. However, if after you do that you run something like "show collections" it will create the empty database.

    I agree, an option to control this behavior would be great. Happy to vote for it if you open a Jira ticket at mongoDB.

提交回复
热议问题