Context
In our app, we permit to our users to upload files, which will be placed in a queue for review and approbation.
User's file ID will be stored as a "sub-list" (I don't know the name) in the user specific Mongo Database.
Question summary
My question is all about defining a file Object ID as a key in my user database and the getting this user's uploaded file ID to retrieve the current file state
value.
Our model
public class User
{
[BsonId]
public string Id { get; set; }
public string email { get; set; } = string.Empty;
public bool hasAcceptedTerms { get; set; } = false;
public IList<UserFile> SubmittedFiles { get; set; }
}
public class UserFile
{
public string fileID { get; set; } // Correspond to the Object Id of a file
public bool hasFile { get; set; }
}
public class File
{
[BsonId]
public string Id { get; set; }
public string fileServerIdentifier { get; set; } = string.Empty;
public string filename { get; set; } = string.Empty;
public string user { get; set; } = string.Empty; //Corresponds to the user object Id
public int state { get; set; } = 0;
}
Mongo JSON database example
{
"files" : {
"5349b4ddd2781d08c09890f3" : {
"fileServerIdentifier" : "7e1fed29-c3b2-4d7e-9e00-bbff38aecb51",
"filename" : "document.pdf",
"user" : "507f1f77bcf86cd799439011",
"state": 0
}
},
"users" : {
"507f1f77bcf86cd799439011" : {
"email" : "username@domain.com",
"hasAcceptedTerms" : true,
"submitted-files" : {
"5349b4ddd2781d08c09890f3" : true
}
}
}
}
My question
First of all, is my link between User and File correct: I mean the
public IList<UserFile> SubmittedFiles { get; set; }
?How can I add, in an existing
users
collection (user filtered by Id), a fileID as a key with valuetrue
.And as a matter of consequence how to retrieve recursively all the
fileID
which are keys and not values so I can use them to retrieve recursively the correspondingstate
inFile
database?