I have a Schema:
exports.participant = function(mongodb){
var participantSchema = new mongoose.Schema({
uniqueid: {type: String, unique: true},
channel: String,
conference: String,
calleridnum: String,
calleridname: String,
event: String,
status : { type: Boolean, default: 0 }
},{ collection: 'participants'});
var participant = mongodb.model('Participant', participantSchema);
return participant;
}
I have already tried how to update a object in mongodb via mongoose, but still it doesn't work for me.
I want to update status to 1
I am calling the update code here . .
the file location of my schema is: ../models/app.js
the file location of my update is: ../lib/update.js
This is my update code . .
var appInit = require('../app');
var logger = appInit.logger;
var basedir = appInit.basedir;
var connection = appInit.connection;
var mongodb = appInit.mongodb;
var handleAsteriskAmi = require(basedir+'/lib/handleasteriskami');
var asteriskAmi = new handleAsteriskAmi();
var handleHttpProc = require(basedir+'/lib/handlehttpproc');
var httpProc = new handleHttpProc();
function handleSocketio(){
this.init = function(io){
io.sockets.on('connection',function(socket){
if(socket){
logger.info("socket.io is connected");
}
socket.on('disconnect', function () {
logger.error("Socket.io is disconnected");
});
socket.on('action', function(data){
var result = JSON.parse(JSON.stringify(data));
asteriskAmi.listenActionConfbridge(result,function(response){
logger.info(JSON.stringify(response));
if(response.event=="originate"){
io.sockets.emit("response",response);
}
if(response.event=="confbridgemute" || response.event=="confbridgeunmute"){
io.sockets.emit("response",response);
mongodb.model("Participant").update(
{channel: response.channel},
{$set: {status: 1}}
);
}
if(response.event=="confbridgelock" || response.event=="confbridgeunlock"){
io.sockets.emit("response",response);
}
});
});
});