私はEbay APIから2つのサービスを利用しようとしています: findItemsByKeywords(keyword)
:アイテム(オブジェクト)のリストを返します。 getItemTransactions(itemId)
:アイテムのトランザクション(オブジェクト)のリストを返します。別の約束の中で約束を(ループで)呼び出すことはできますか?
findItemsByKeywords
を呼び出して返品後の商品リストを取得した後、getItemTransactions
に電話してその商品のそれぞれの取引を取得し、それらの商品で新しいリストを作成する必要があります。
私は私のコードは唯一つの相互作用のために働くのNode.js、エクスプレス、EJSとMongoDBの
を使用しています。
Error:
Error: unable to connect to database at mongodb://localhost/simplysell-development
at NativeConnection.<anonymous> (/Users/guilhermefalcao/workspace/simplysell/app.js:11:9)
at emitOne (events.js:96:13)
at NativeConnection.emit (events.js:188:7)
at Db.<anonymous> (/Users/guilhermefalcao/workspace/simplysell/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js:169:10)
at emitTwo (events.js:106:13)
at Db.emit (events.js:191:7)
at Server.listener (/Users/guilhermefalcao/workspace/simplysell/node_modules/mongodb/lib/db.js:1786:14)
at emitOne (events.js:96:13)
at Server.emit (events.js:188:7)
at Server.<anonymous> (/Users/guilhermefalcao/workspace/simplysell/node_modules/mongodb/lib/server.js:274:14)
at emitOne (events.js:96:13)
at Server.emit (events.js:188:7)
at Pool.<anonymous> (/Users/guilhermefalcao/workspace/simplysell/node_modules/mongodb-core/lib/topologies/server.js:334:12)
at emitOne (events.js:96:13)
at Pool.emit (events.js:188:7)
at Connection.<anonymous> (/Users/guilhermefalcao/workspace/simplysell/node_modules/mongodb-core/lib/connection/pool.js:270:12)
私はデータベースにアクセスしようとしていませんが、なぜこのエラーが発生するのかわかりません。
コードと英語の品質についてお詫び申し上げます。私は今から始めていますです。
router.get('/bestsellers', (req, res, next) => {
var i = 0;
var findItemsByKeywordsPromise = findItemsByKeywords('iphone');
findItemsByKeywordsPromise.then(items => {
var getItemTransactionsPromise = getItemTransactions(items);
return getItemTransactionsPromise;
}).then(test => console.log(test))
});
function getItemTransactions(items) {
return new Promise((resolve, reject) => {
var list = [];
items.forEach(function (item) {
ebay.xmlRequest({
serviceName: 'Trading',
opType: 'GetItemTransactions',
// app/environment
devId: 'xxxxxxx',
certId: 'xxxxxxx',
appId: 'xxxxxxx',
sandbox: false,
// per user
authToken: 'xxxxxxx',
params: {
'ItemID': item.itemId,
'NumberOfDays': 30
}
}, function (error, results) {
list.push(results)
resolve(list);
});
})
});
}
function findItemsByKeywords(keywords) {
return new Promise((resolve, reject) => {
var params = {
keywords: [keywords],
};
ebay.xmlRequest({
serviceName: 'Finding',
opType: 'findItemsByKeywords',
appId: 'xxxx', // FILL IN YOUR OWN APP KEY, GET ONE HERE: https://publisher.ebaypartnernetwork.com/PublisherToolsAPI
params: params,
parser: ebay.parseResponseJson // (default)
},
// gets all the items together in a merged array
function itemsCallback(error, itemsResponse) {
if (error) reject(error);
console.log('findItemsByKeywords called');
var items = itemsResponse.searchResult.item;
console.log('Found', items.length, 'items');
resolve(items);
}
);
});
}
あなたの依存関係は何ですか?私はしばしばこのエラーをMongooseのようなパッケージを含めて実際にmongodbサーバを起動させないようにしました。だから、どちらかのアウト/コメントパッケージを削除するか、MongoDBの –
@CodyGuldner するvar急行=( '表現')が必要です、 ルータ= express.Router()、 マングース=が( 'マングース')を要求し、 条=マングースを開始します。モデル( 'Article'); var ebay = require( 'ebay-api'); –
あなたのmongoクライアントが起動していることを確認してください、またはエラーが発生します –