我正在尝试更新集合中的值。用户单击一个按钮,与该按钮对应的数字会被发送到服务器以添加到集合中。
我无法更新集合,但如果我使用它在控制台中可以正常工作db.orders.update()
订货型号:
// DB Initiation stuff
var orderSchema = new mongoose.Schema({
status: String,
rated: Number
});
var collection = 'orders';
var Order = db.model('Order', orderSchema, collection);
module.exports = Order;
客户端(单击按钮时)
// starID = 5; id = 50e6a57808a1d92dcd000001
socket.emit('rated', {rated: starID, id: id});
socket.js:
var Order = require('../models/orders');
socket.on('rated', function(data) {
/* Probably a better way to do this but, wrap
* the id in 'ObjectId(id)'
*/
var id = 'ObjectId("'+data.id+'")';
Order.update( {_id: id}, {$set: {rated: data.rated}} );
socket.emit('updated', {
note: 'Some HTML notification to append'
});
});