嘿伙计们,我正试图像这样使用Meteor upsert。
console.log(vendorReviewArr);
var updateQuery = {$set: {vendorID: vendorIDVal}, $push: {reviews:vendorReviewArr}};
VendorReviews.upsert(
{vendorID: vendorIDVal},
updateQuery,
function(error){
console.log("There is an error!");
console.log(error);
console.log("VENDOR ID: "+vendorIDVal);
}
);
vendorReviewArr在console.log中看起来像这样。
{ title: 'This is a test title title title',
body: 'This is a test title body' }
这是VendorReviews的简单版。
VendorReviews = new Mongo.Collection('vendorsReviews'); //Define the collection.
VendorReviewObjSchema = new SimpleSchema({
authorID: {
type: String,
label: "authorID",
autoValue: function(){
return this.userId
},
optional: true
},
title: {
type: String,
label: "title",
min: 25,
},
body: {
type: String,
label: "body",
min: 25,
max: 1000
}
});
VendorReviewsSchema = new SimpleSchema({
vendorID: {
type: String,
label: "vendorID HERE",
},
reviews : {
type : [VendorReviewObjSchema],
label : "Vendor Reviews",
optional: true
}
});
VendorReviews.attachSchema(VendorReviewsSchema);
现在出于某种原因,从服务器调用此方法时,集合不会记录任何数据。我所看到的只是
I20160110-23:54:38.031(-5)? There is an error!
I20160110-23:54:38.032(-5)? null
I20160110-23:54:38.032(-5)? VENDOR ID: iXdqzcSNmMwrRj3jf
检查mongo shell中的集合显示没有数据。
有人可以帮我解决这个问题吗?谢谢你的阅读。