0
我得到這個錯誤類型錯誤:不能使用「在」運營商{}
*TypeError: Cannot use 'in' operator to search for '_id' in {
at model.Document.$__buildDoc (C:\Users\seanr\projects\DerrickAlphaFebTest\node_modules\mongoose\lib\document.js:210:27)
at model.Document (C:\Users\seanr\projects\DerrickAlphaFebTest\node_modules\mongoose\lib\document.js:61:20)
at model.Model (C:\Users\seanr\projects\DerrickAlphaFebTest\node_modules\mongoose\lib\model.js:51:12)
at new model (C:\Users\seanr\projects\DerrickAlphaFebTest\node_modules\mongoose\lib\model.js:3571:13)
at Request._callback (C:\Users\seanr\projects\DerrickAlphaFebTest\routes.js:24:27)
at Request.self.callback (C:\Users\seanr\projects\DerrickAlphaFebTest\node_modules\request\request.js:188:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request.<anonymous> (C:\Users\seanr\projects\DerrickAlphaFebTest\node_modules\request\request.js:1171:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at IncomingMessage.<anonymous> (C:\Users\seanr\projects\DerrickAlphaFebTest\node_modules\request\request.js:1091:12)
at IncomingMessage.g (events.js:291:16)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)*
當我試圖創建我的MongoDB貓鼬模型來搜索「_id」。我試圖通過響應數據循環並將其保存在我的MongoDB中。
模型/訂單模式:
var mongoose = require('mongoose'),
bcrypt = require('bcryptjs'),
config = require('../config/database');
var Schema = mongoose.Schema;
var OrderSchema = new Schema({
orders: Object
});
var Orders = mongoose.model('Orders', OrderSchema);
module.exports = Orders;
woocommerce認證:
WooCommerceAPI = require('woocommerce-api');
var WooCommerce = new WooCommerceAPI({
url: 'https://www.example.com',
consumerKey: 'ck_example',
consumerSecret: 'cs_example',
wpAPI: true,
version: 'wc/v1',
queryStringAuth: true
})
GET請求並保存到貓鼬模式:
WooCommerce.get('orders', function(err, data, res){
console.log(res);
for(var orders in res){
var O = new Orders(orders);
O.save();
}
});
res
是一個JSON對象。
另注:它仍然保存到我的數據庫出於某種原因,但它幾乎一樣,如果它是一個無限循環,因爲這樣可以節省更多的數據,然後我的預期。我很少有使用for-in循環的經驗,但認爲這是解決這個問題的最好方法。如果您對我出錯的地方有任何瞭解,我將不勝感激!
什麼類型'這裏res'? – Saravana
它是一個JSON對象。 –
s.renton大家好,歡迎到堆棧溢出。你能否提供關於錯誤的更多細節 - 例如它是否來自你引用的代碼行之一? –