Can not delete collection from mongodb

前端 未结 3 1168
甜味超标
甜味超标 2021-01-01 12:36

Can not delete the collection from the shell,

The thing that the collection is available and my php script is accessing it (selecting|updating)

But when I us

相关标签:
3条回答
  • 2021-01-01 12:53

    For some reason the double quotes "_registration" did not workfor me .. but single quote '_registration' worked

    0 讨论(0)
  • 2021-01-01 12:59

    You can also use:

    db["_registration"].drop()
    

    which syntax works in JS as well.

    0 讨论(0)
  • 2021-01-01 13:13

    The problem is not with deleting the collection. The problem is with accessing the collection. So you would not be able to update, find or do anything with it from the shell. As it was pointed in mongodb JIRA, this is a bug when a collection has characters like _, - or .

    Nevertheless this type of names for collections is acceptable, but it cause a problem in shell.

    You can delete it in shell with this command:

    db.getCollection("_registration").drop()
    

    or this

    db['my-collection'].drop()
    

    but I would rather rename it (of course if it is possible and will not end up with a lot of changing).

    0 讨论(0)
提交回复
热议问题