Mongodb 如何在meteor.call方法中发送ISODate
我正在meteor的客户端创建一个对象数组,每个对象都修改了其中的日期,如下所述: 客户端:Mongodb 如何在meteor.call方法中发送ISODate,mongodb,meteor,Mongodb,Meteor,我正在meteor的客户端创建一个对象数组,每个对象都修改了其中的日期,如下所述: 客户端: student; 这里的student是一个对象数组,包含名称、id、卷号 var array = []; student.forEach(function(singleStud, index){ var single_obj ={ "name":singleStud.name, "student_id":singleStud.id, "roll_no":singleStud.
student;
这里的student
是一个对象数组,包含名称、id、卷号
var array = [];
student.forEach(function(singleStud, index){
var single_obj ={
"name":singleStud.name,
"student_id":singleStud.id,
"roll_no":singleStud.roll_no,
"college_name":"ABC college",
"college_id":"xyz Id",
"created_date": new Date()
}
array.push(single_obj);
},this)
Meteor.call('saveDetails', array, function (error, result) {
console.log("data Saved Successfully");
});
服务器端:
student;
我使用插件插入了一个数组,相当于mongo中的insertMany
Meteor.methods({
"saveDetails": function (array) {
try {
studentDetails.batchInsert(array);
return true;
} catch (err) {
return err;
}
}
});
当我保存它时,created\u date
将其保存为字符串(“2018-04-23T10:26:26.766Z”
),但我希望它保存为日期数据类型(ISODate(“2018-04-23T10:26:26.766Z”)
)
如何在meteor.call中从客户端实现
这实际上是mikowals:batch insert
中的一个bugmikowals批插入
递归地尝试将对象转换为与MongoDB友好的JSON格式。作为此过程的一部分,它使用来创建基元类型。虽然Date
是一个原语,但它不能用\uu.clone
进行克隆,因此它会将日期变为字符串(eww)。您应该使用mikowals:batch insert
打开一个问题
无论如何,不应在客户端上定义此数据。客户端可能恶意注入错误信息(这可能会破坏应用程序的逻辑)。相反,您应该映射输入并将日期注入传入对象
你能console.log
方法调用中的数组吗?