如何在RethinkDB中创建唯一项?
在MongoDb中我使用ensureIndex
了这个,例如:
userCollection.ensureIndex({email:1},{unique:true},function(err, indexName){
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个预处理程序,在写入MongoDB之前清理所有数据,请参阅:http://mongoosejs.com/docs/middleware.html
我尝试过以下方法让每个房产都能清理它:
blogSchema.pre('save', function (next) {
var obj = this;
console.log(obj)//-> https://gist.github.com/daslicht/70e0501acd6c345df8c2
// I've tried the following to get the single items :
Object.keys(obj).forEach(function (key) {
console.log('Keys: ',obj[key]);
});
//and:
for(var key in obj) {
console.log(obj[key])
}
//and:
_.each( self , function(value, key, list){
console.log('VALUE:',key);
})
next();
})
Run Code Online (Sandbox Code Playgroud)
上述任何一种方法都会产生如下情况:
这是输出:
for(var key in obj) {
console.log(obj[key])
}
Run Code Online (Sandbox Code Playgroud)
https://gist.github.com/daslicht/cb855f53d86062570a96
有谁知道如何获得每个单一的财产,以便我可以消毒它,好吗?
〜马克
[编辑]这是一个可能的解决方法,无论如何,将它直接放在Scheme级别会更干净,因为这样会更干
var post = {
createdAt : req.body.date,
createdBy : req.user.username,
headline : req.body.headline,
content : req.body.content …
Run Code Online (Sandbox Code Playgroud) 如何在Angular2/TypeScript/AngularFire2中实例化Firebase云消息传递?
这里针对JavaScript进行了描述:https: //firebase.google.com/docs/cloud-messaging/js/client
firebase typescript firebase-cloud-messaging angularfire2 angular
在研究了一些中间件后,我还有一个问题.
看看下面的工作设置,它只是将do it函数附加到req对象,以便我们可以在任何路径中调用它 req.doit()
但是,req,res,next来自哪里?,我从未通过它们,我更加好奇它是如何工作的,因为匿名函数(2.)被另一个函数(1.)包围,我甚至可以传递参数.
MiddleWareTest.js:
var test = function(options){ //1.)
return function(req, res, next) { //2.)
req.doit = function() {
console.log('doit')
}
next();
}
}
module.exports = test;
Run Code Online (Sandbox Code Playgroud)
app.js:
...
var myMiddleware = require('./MiddlewareTest.js')
app.use(myMiddleware())
...
Run Code Online (Sandbox Code Playgroud)
欢迎任何加深我知识的建议:)
〜马克
express ×2
node.js ×2
angular ×1
angularfire2 ×1
connect ×1
firebase ×1
mongoose ×1
rethinkdb ×1
typescript ×1