Tuesday 6 June 2017

MongoDB define collection that has an array as document

I'm a newbie to mongodb and I'm trying to create my first database.

This is my scenario: A user can connect to a FTP Location and get/put some files. Each user can have more than one FTP Storage that he can access.

These are the fields required for the user document:

username: String  
password: String

And these are the fields required for the ftp document:

host: String  
port: Number  
user: String  
pass: String

And here comes my question...Can I have a single collection that contains both documents mentioned above?

More precisely, I need to know how I can get a record like this and how my database should look...

username: "User",  
password: "test",
[
  {
    host: "first-host",  
    port: 21,  
    user: "defined-user",  
    pass: "defined-pass",
  },
  {
    host: "second-host",  
    port: 21,  
    user: "defined-user",  
    pass: "defined-pass",
  }
]

Not sure if my question is clearly enough, but please let me know if I need to specify additional information to get some answers



via Valip

No comments:

Post a Comment