我正在尝试使用mongoose> 4.0.0的新不稳定版本来验证更新查询.
说我想使用以下查询更新架构
schema.update({_id:'blah'},{a:'blah'},function(err){
//do your thing
})
Run Code Online (Sandbox Code Playgroud)
所以我说我有以下架构,
var schema = new Schema({
a:{type:String}
});
schema.pre('update',function(next){
var findQuery=this._conditions; // gives {_id:'blah'}
// how do i get {a:'blah'}????
next();
});
Run Code Online (Sandbox Code Playgroud)
如何在预中间件中获得{set:{a:'blah'}}的更新查询,以便在执行更新之前进行一些检查?
或者我知道更新查询可以在后中间件中访问
schema.post('update',function(){
var findQuery=this._conditions; // gives {_id:'blah'}
var updateQuery=this._update; //gives {$set:{a:'blah'}}
next();
});
Run Code Online (Sandbox Code Playgroud)
但为时已晚,我需要在预先中间件中进行检查才能实际更新数据库.
我尝试查看预中间件的'this'对象,但无法在任何地方找到updateQuery对象,并且this._update在预中间件中未定义.
有没有办法做到这一点?谢谢
对于我的项目,我有很多函数对单个全局变量进行更改,但是由于文件非常大,我想将这些函数拆分为不同的模块。但是,当传递全局变量时,它会创建另一个实例。有没有办法防止这种情况?
例如,这是所需的输出:
var global_var=1;
function first_function(){
console.log(++global_var);
}
function second_function(){
console.log(++global_var);
}
first_function(); //outputs 2
second_function(); //outputs 3
first_function(); //outputs 4Run Code Online (Sandbox Code Playgroud)
但是当试图将 first_function 和 second_function 分成不同的模块时,
//in main.js file
var global_var=1;
var first_function=require(./first_function)(global_var);
var second_function=require(./second_function)(global_var);
first_function(); //outputs 2
second_function(); //outputs 2
first_function(); //outputs 2
//in first_function.js and second_function.js
module.exports=function(global_var){
return ++global_var;
}Run Code Online (Sandbox Code Playgroud)
我不想在每次进行函数调用时重新分配或重新传输 global_var,因为更改 global_var 的函数调用每分钟进行数千次,而 global_var 是一个具有 1000 多个键的对象。
有没有办法确保子模块在不传递全局对象的情况下修改全局对象的相同实例?
我使用 MediaRecorder api 成功录制了网络摄像头,但生成的文件大小对于其质量来说似乎太大了。
例如,对于 480x640 的 8 秒视频,我得到的文件大小为 1mB。这似乎不对。
我要记录的代码()
navigator.mediaDevices.getUserMedia({video: true, audio: true})
.then(function(stream){
var options = {
mimeType : "video/webm;codecs=vp9"
//I don't set bitrate here even if I do the quality is too bad
}
var media_recorder = new MediaRecorder(media_stream, options);
var recorded_data = [];
media_recorder.ondataavailable = function(e){
recorded_data.push(e.data);
}
media_recorder.onstop = function(e){
recorded_data.push(e.data);
var recorded_blob = new Blob(recorded_data, { 'type' : 'video/webm; codecs=vp9' });
var recorded_video_url = window.URL.createObjectURL(recorded_blob);
//here I write some code to download the …Run Code Online (Sandbox Code Playgroud) 在 64 位 x86 汇编 nasm 中,如何将单个字节从寄存器移动到 .data 节中定义的内存位置?
我明白这有效
global _main
section .data
quotient db 0x0, 0x0, 0x30, 0xa ; 3 digit + newline
remainder db 0x0, 0x0, 0x30, 0xa; 3 digit + newline
section .text
_main:
mov rax, 0x2000004
mov rdi, 1
mov rsi, quotient
mov rdx, 8
syscall ; outputs 0 /newline 0 /newline as expected
exit:
mov rax, 0x2000001
mov rdi, 0
syscall
Run Code Online (Sandbox Code Playgroud)
我还知道您可以使用 byte 关键字设置单个字节
mov rbx, quotient ; move location of quotient into memory …Run Code Online (Sandbox Code Playgroud)