MongoError。 (不可变的)字段' _id'被发现被改为_id

时间:2017-02-24 22:38:41

标签: node.js mongodb mongoose

这是我的users.js(路线)

                  for(var zz =0;zz < d.length; zz++){
                    tempfinance = {}; 
                    tempfinance.sellerId = sellerId;
                    tempfinance.AmazonOrderId = d[zz].AmazonOrderId;
                    tempfinance.MarketplaceName = d[zz].MarketplaceName;
                    tempfinance.OrderChargeList = d[zz].OrderChargeList;
                    tempfinance.OrderChargeAdjustmentList = d[zz].OrderChargeAdjustmentList;
                    tempfinance.ShipmentFeeList = d[zz].ShipmentFeeList;
                    tempfinance.SKU = d[zz].ShipmentItemList.ShipmentItem[j].SellerSKU;
                    tempfinance.ShipmentFeeAdjustmentList = d[zz].ShipmentFeeAdjustmentList;
                    tempfinance.OrderFeeList = d[zz].OrderFeeList;
                    tempfinance.OrderFeeAdjustmentList = d[zz].OrderFeeAdjustmentList;
                    tempfinance.DirectPaymentList = d[zz].DirectPaymentList;
                    tempfinance.PostedDate = d[zz].PostedDate;
                    tempfinance.transactiontype = 'Sales';

                    tempfinance.ItemFeeList = d[zz].ShipmentItemList.ShipmentItem[j].ItemFeeList;
                    tempfinance.ItemChargeList = d[zz].ShipmentItemList.ShipmentItem[j].ItemChargeList;
                    tempfinance.promotionlist = d[zz].ShipmentItemList.ShipmentItem[j].PromotionList;
                    // console.log(tempfinance);


                   var query = { sellerId: sellerId, AmazonOrderId: tempfinance.AmazonOrderId, SKU:tempfinance.SKU,transactiontype:'Sales'};
                    var update = { '$set': tempfinance};
                    var options = { new: true, upsert: true };
                    orderdata.findOneAndUpdate(query, update, options, function(err, user) {
                        // console.log('ERROR--'+err)
                        if (err) throw err;
                    });
              }

这是我的模型(orderdata)mongoose schema:

var mongoose = require('mongoose');

mongoose.Promise = global.Promise;

var mongoosePaginate = require('mongoose-paginate');

var options = {
    server: { auto_reconnect: true, socketOptions: { socketTimeoutMS: 100000, connectTimeoutMS: 100000, maxTimeMS: 100000 } }
    // replset: { socketOptions: { keepAlive:300000, connectTimeoutMS:0}}
};
mongoose.createConnection('mongodb://localhost:27017/ca');

var db = mongoose.connection;

// User Schema
var UserSchema = mongoose.Schema({

    sellerId: {
        type: String
    },
    AmazonOrderId: {
        type: String
    },
    SKU: {
        type: String
    },
    orderitemid: String,
    MarketplaceName: String,
    transactiontype: String,
    OrderChargeList: {},
    OrderChargeAdjustmentList: {},
    ShipmentFeeList: {},
    ShipmentFeeAdjustmentList: {},
    OrderFeeList: {},
    OrderFeeAdjustmentList: {},
    DirectPaymentList: {},
    ItemFeeList: {},
    ItemChargeList: {},
    promotionlist: {},
    PostedDate: String,
    FullfillmentData: {},
    PurchaseDate: String,
    ASIN: String,
    OrderItem: {},
    fulfillmentid: String,
    taxrate: String,
    Taxreportstatus: String
        // adjustmentamount: String

    // finance : {},
    // refundfinance: {}



});
UserSchema.plugin(mongoosePaginate);

module.exports = mongoose.model('orderdata', UserSchema);

请帮助。 提前致谢!

1 个答案:

答案 0 :(得分:0)

很长时间但是查看错误消息似乎您的查询正在尝试更新(即使具有相同的值)集合的_id