我将以下集合附加到aldeed:simple schema
public List<int[][]> AllSharesForFiles (int n , int k,List<File> file) {
sharesHolder = new LinkedList<int[][]>();
try{
for(int i=0;i<file.size();i++) {
byte[]secret = f.readingTheFile(file.get(i)); // We call the method which read the file
//method which evaluate the shares of each byte of the file
shar1= s.calculateThresholdScheme(secret, n,k,new RndGeneratorAllAlgorithm(new RandomGeneratorSHA1()),two);
sharesHolder.add(shar1);
}
} catch (IOException e) {
e.printStackTrace();
}
return sharesHolder;
}
/*Look for the possibilities to return a 2D array instead of one dimensional array
*
*/
public List<int[][]> AllSharesForEachFile (int n , int k,List<int [] []> f) {
sharesHolder1 = new LinkedList<int[][]>();
int s=f.size();
int l=f.get(1)[0].length;
for (int i = 0; i < n; i++) {
someValue=new int[s][l];
for(int j=0;j<f.size(); j++){
someValue[j]=f.get(j)[i];
}
sharesHolder1.add(someValue);
}
return sharesHolder1;
}
实际文件如下所示:
Posts = new Mongo.Collection("posts");
Posts.attachSchema(new SimpleSchema({
samplePost:{
type:String,
max:500
},
createdAt:{
type: Date,
autoValue: function(){
return new Date()
}
},
"comments.$.reply":{
type:String
},
"comments.$.commentId":{
type: String,
autoValue: function(){
var tempCommentId = new Meteor.Colletion.ObjectID();
return tempCommentId.str;
}
},
"comments.$.commentCreatedAt": {
type: Date,
optional: true,
autoValue: function(){
return new Date()
}
},
});
现在我试图用带有$ pull的文档中的commentId:“ccc”删除第二条评论
{
"_id": "aaa",
"samplePost": "Hello world!",
"comments": [
{
"reply": "Goodbye",
"commentId": "bbb",
"createdAt": "2016-06-19T19:06:17.931Z"
},
{
"reply": "Good morning",
"commentId": "ccc"
"createdAt": "2016-06-19T19:05:17.931Z"
},
]
}
这不起作用。我把问题缩小到了
"click #delete-comment": function(event, template){
var tempCommentId = $(event.target).parent().find('#commentIdPass').text(); //commentId is collected from HTML view
Posts.update(
{_id: template.data._id}, //_id is collected from the url param
{$pull:{
comments: {
commentId: tempCommentId
}}
});
},
架构。如果我删除此架构,我可以删除评论。 那么,为什么这会导致从数组中拉出整个注释项的问题。有任何想法吗?任何解决方法?
答案 0 :(得分:0)
尝试此查询:
。db.getCollection( 'MYTEST')更新({ “_编码”: “AAA”},{ “$拉”:{ “评论”:{ “commentId”: “CCC”}}});
答案 1 :(得分:0)
发现问题。因为我怀疑附加架构是罪魁祸首。我需要为使用autovalue方法插入和更新模式设置条件。架构应如下所示:
"comments.$.commentCreatedAt": {
type: Date,
autoValue: function () {
if (this.isInsert) {
return new Date;
}
}
},