mongodbmongodb-queryinsert-updatealter-table

How to alter a table using mongodb


I need to add a new field for 'status' on MongoDB collection. I got so many tutorials but it never point-out the type of field. I need an varchar(5)

Is the below snippet is right for my requirement.

db.users.update(
    { },
    { $set: { Status: []} },
    { multi: true }
)

Solution

  • MongoDB does not use tables. Use Collections, maybe you must study deeper this concepts because you must change the classic E/R mind to the new concept (Collections).

    I recommend you to use mongoose and define your models with JSON. There are tons of tutorials and documentation about this.

    EDIT:

    As I mentioned before try to use this if you are using a high level language. http://mongoosejs.com/ It's very simple and works perfectly.

    If you are using commands directly in your mongo shell read this link. http://docs.mongodb.org/manual/reference/mongo-shell/

    You will get essentials concepts as collections, how can be this collections transformed in a dynamic, lazy way.