如何在 meteor.call 方法中发送 ISODate
How to send ISODate in meteor.call method
我正在 meteor 的客户端创建一个对象数组,每个对象都在其中修改了日期,如下所述:
客户端:
student;
这里student
是一个包含对象的数组name, id, roll_no
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");
});
服务器端:
我使用插件 mikowals:batch-insert 插入了一个数组,相当于 mongo 中的 insertMany
。
Meteor.methods({
"saveDetails": function (array) {
try {
studentDetails.batchInsert(array);
return true;
} catch (err) {
return err;
}
}
});
当我保存它时,created_date
将其保存为字符串 ("2018-04-23T10:26:26.766Z"
),但我希望将其保存为日期数据类型 (ISODate("2018-04-23T10:26:26.766Z")
)。
如何在 meteor.call
中从客户端实现???
这实际上是 mikowals:batch-insert
中的一个错误。 mikowals-batch-insert
递归地尝试将对象转换为对 MongoDB 友好的 JSON 格式。作为此过程的一部分,它使用 underscore clone to make shallow copies 原始类型。虽然 Date
是原语,但不能用 _.clone
克隆它,因此它会将您的日期变异为字符串 (eww)。你应该用 mikowals:batch-insert
.
打开一个问题
无论如何,您 不应该在客户端定义此数据。 客户端可能会恶意注入虚假信息(这可能会破坏您的应用程序的逻辑)。相反,您应该映射输入并将日期注入传入对象。
我正在 meteor 的客户端创建一个对象数组,每个对象都在其中修改了日期,如下所述:
客户端:
student;
这里student
是一个包含对象的数组name, id, roll_no
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");
});
服务器端:
我使用插件 mikowals:batch-insert 插入了一个数组,相当于 mongo 中的 insertMany
。
Meteor.methods({
"saveDetails": function (array) {
try {
studentDetails.batchInsert(array);
return true;
} catch (err) {
return err;
}
}
});
当我保存它时,created_date
将其保存为字符串 ("2018-04-23T10:26:26.766Z"
),但我希望将其保存为日期数据类型 (ISODate("2018-04-23T10:26:26.766Z")
)。
如何在 meteor.call
中从客户端实现???
这实际上是
mikowals:batch-insert
中的一个错误。mikowals-batch-insert
递归地尝试将对象转换为对 MongoDB 友好的 JSON 格式。作为此过程的一部分,它使用 underscore clone to make shallow copies 原始类型。虽然Date
是原语,但不能用_.clone
克隆它,因此它会将您的日期变异为字符串 (eww)。你应该用mikowals:batch-insert
. 打开一个问题
无论如何,您 不应该在客户端定义此数据。 客户端可能会恶意注入虚假信息(这可能会破坏您的应用程序的逻辑)。相反,您应该映射输入并将日期注入传入对象。