in App.js I call:
Meteor.call(‘orders.newBuyLimit’, this.state.marketName, this.state.price, Meteor.userId(), name, this.state.marketName.maxValue)
in orders.js I have:
if(Meteor.isServer){
// This code only runs on the server
Meteor.publish('orders', function ordersPublication() {
return Orders.find();
});
Meteor.methods({
'orders.newBuyLimit'(marketName, price, user, userName, maxPrice) {
findOneAndUpdate=Meteor.wrapAsync(Orders.rawCollection().findOneAndUpdate)
try{
const response = findOneAndUpdate(
{
$and: [
{sellerActive:1},
{sellerExists:1},
{marketName:marketName},
{price: {$lt:price}},]
},
{
$set: {
buyerId:user,
buyerPrice:price,
buyerExists:1,
buyerActive:1,
buyerTime: new Date(),
buyerResult:1.01*price,
buyerName:userName,
marketName:marketName,
}
},
{
sort: {
price: 1
}
},
{
upsert:true,
returnNewDocument:true,
},
function(err,result) {
if ( err ) {
console.warn(err);
} else {
console.log(result);
}});
} catch (err) {
throw new Meteor.Error(err);
}
},
};