2013-01-12 7 views
1

에서 시간을 포함하는 쿼리를 수행하는 서버의를 사용하는 방법은 무엇입니까 데이터 삽입 시점의 클라이언트 시간 대신 시간?는 유성 ​​클라이언트

new Date();을 사용하면 클라이언트의 시간이 달라질 수 있으므로 일치하지 않을 수 있습니다.

나는 쿼리를 삽입하기 전에 서버의 시간을 가져올 수 있지만 삽입 명령이 서버로 다시 보내지는 것을 고려하면 약간 중복 된 것처럼 보입니다.

답변

1
당신은 단순히 이미 전송 - 투 - 서버 중복을 피하기 위해이 작업을 수행 할 수

:

if (Meteor.isClient) { 
    Meteor.call("getDate", function (error, result) { 
     Collection.insert({"name":"Record 1", creationTime: result}); 
    }); 
} 


if (Meteor.isServer) { 
    Meteor.methods({ 
     getDate: function() { 
      return new Date(); 
     } 
    }); 
} 
:
if (Meteor.isClient) { 
    Meteor.call("addItem", {"name": "Record 1"}); 
} 

if (Meteor.isServer) { 
    Meteor.methods({ 
     "addItem": function(obj) { 
      obj.creationTime = new Date(); 
      Collection.insert(obj); 
     }  
    }); 
} 

또는 클라이언트에서