난 작은 내가 일하고 응용 프로그램과 내가해야 할 한 가지의 일환으로 패키지를 작성하고 엔드 포인트에서 JSON 데이터를 가져올하고 그것을 채우는 것입니다 JSON 엔드 포인트에서 서버 측 콜렉션에 채우기 서버 측 컬렉션.유성 0.9.1.1 -
서버 측 콜렉션 업데이트 기능을 Fiber, Meteor.bindEnvironment 또는 Meteor._callAsync에 넣어야한다는 오류 메시지가 표시됩니다.
내가 정확히 무엇을하는지, 언제 사용하지 않을 것인지, 사용법을 잘 모르는 지에 대해 명확하고 간결한 설명이 없기 때문에 나는 당혹 스럽다. 여기
내 패키지 파일 내의 중요한 것이 무엇인지를 살펴입니다api.addFiles([
'_src/collections.js'
], 'server');
사이비 코드의 비트 :
1) Mongo.Collection 항목의 목록을 설정
2) 성공적이었다 가져올 경우 해결 약속을 반환, 내가라고 쓴 함수 httpFetch()를 사용하여 이러한 채우기 각각의 컬렉션에 대한이를 실행합니다.
3) 밑줄 each() 루프 내에서이 httpFetch 함수를 호출하여 내가 가진 각 컬렉션을 거치며 json 데이터를 가져 와서 서버 측 Mongo DB에 삽입하려고 시도합니다.
Collections.js 아래 무엇처럼 보인다. 파이버에서 삽입 기능을 래핑하면 오류 메시지가 표시되지 않지만 데이터가 DB에 삽입되지 않습니다.
/**
* 서버 측 구성 요소는 원격 요청 * 서버 측 몽고 컬렉션을 채울 엔드 포인트를합니다. * * @class 서버 @static * */ 서버 = {
Fiber: Npm.require('fibers'),
/**
* Collections to be populated with content
*
* @property Collections
* @type {Object}
*/
Collections: {
staticContent: new Mongo.Collection('staticContent'),
pages: new Mongo.Collection('pages'),
projects: new Mongo.Collection('projects'),
categories: new Mongo.Collection('categories'),
formations: new Mongo.Collection('formations')
},
/**
* Server side base url for making HTTP calls
*
* @property baseURL
* @type {String}
*/
baseURL: 'http://localhost:3000',
/**
* Function to update all server side collections
*
* @method updateCollections()
* @return {Object} - a resolved or rejected promise
*/
updateCollections: function() {
var deferred = Q.defer(),
self = this,
url = '',
collectionsUpdated = 0;
_.each(self.Collections, function(collection) {
// collection.remove();
url = self.baseURL + '/content/' + collection._name + '.json';
self.httpFetch(url).then(function(result) {
jsonData = EJSON.parse(result.data);
_.each(jsonData.items, function(item) {
console.log('inserting item with id ', item.id);
self.Fiber(function() {
collection.update({testID: "Some random data"}
});
});
deferred.resolve({
status: 'ok',
message: 'Collection updated from url: ' + url
});
}).fail(function(error) {
return deferred.reject({
status: 'error',
message: 'Could not update collection: ' + collection._name,
data: error
});
});
});
return deferred.promise;
},
/**
* Function to load an endpoint from a given url
*
* @method httpFetch()
* @param {String} url
* @return {Object} - A resolved promise if the data was
* received or a rejected promise.
*/
httpFetch: function(url) {
var deferred = Q.defer();
HTTP.call(
'GET',
url,
function(error, result) {
if(error) {
deferred.reject({
status: 'error',
data: error
});
}
else {
deferred.resolve({
status: 'ok',
data: result.content
});
}
}
);
return deferred.promise;
}
};
나는 아직도이 문제에 매달 렸고, 다른 게시물을 읽으려고 전에 시도한 것에서는 여전히이 작업을 얻거나 작동하도록하는 '최상의 방법'을 파악할 수 없다. 모든.
는 2011/2012의 제안이 많이 있습니다하지만 유성 사물의 꽤 많이 깰 수 일정한 플럭스, 심지어 사소한 업데이트에 있기 때문에 나는 그들을 사용하기를 꺼려 할 것이다.
감사