我mongoose 3.0.3从npm 使用这个架构:
var schema = new Schema({
_id: Schema.ObjectId,
email: {type: String, required: true, unique: true}
});
Run Code Online (Sandbox Code Playgroud)
如果我尝试保存已经在db中的电子邮件,我希望在省略字段时得到ValidationError类似的信息required.然而事实并非如此,我得到了一个MongoError: E11000 duplicate key error index.
这不是验证错误(即使我删除unique:true也会发生).
知道为什么吗?
我mongoose 3.0.3从npm 使用这个架构:
var schema = new Schema({
_id: Schema.ObjectId,
email: {type: String, required: true, unique: true}
});
Run Code Online (Sandbox Code Playgroud)
使用此中间件从unique:true获取validationError
schema.pre("save", function(next, done) {
var self = this;
model.findOne({email : this.email}, 'email', function(err, results) {
if(err) {
done(err);
} else if(results) {
console.warn('results', results);
self.invalidate("email", "email must be unique");
done(new Error("email must be unique"));
} else {
done();
}
});
next();
});
Run Code Online (Sandbox Code Playgroud)
但是,它不起作用!
Users.create()仍将返回aa MongoError: E11000 duplicate key error index,console.warn()之后才会调用.
在done()根据文档调用所有中间件之前,不应调用保存操作,我应该返回验证错误. …
我正在尝试编写一个指令来加载一个部分html文件,针对一个范围进行编译并将其用作Bootstrap popover内容.
但是我坚持一个非常基本的步骤,在弹出范围内写一个hide()方法,以便我可以轻松地使用它来关闭它ng-click=hide().
这已经解决了,而且现在正在报道其他问题;-).
更新:拯救者:http ://plnkr.co/edit/QH3NQh?p=preview
.directive('uiPopover', ['$compile', '$http', function($compile, $http) {
return {
restrict: 'A',
scope: {
hide: '&hide' // did not understand what is this
},
link: function postLink(scope, element, attr, ctrl) {
console.warn('postLink', arguments, this);
// scope is the anchor scope
scope.name = "Hello"; // Using {{name}} is working
scope.hide = function() { // Using ng-click="hide()" is not working :(
console.log('in');
element.popover('hide');
}
$http.get(attr.uiPopover).success(function(data) {
element.popover({
content: $compile(data)(scope), // popover content will get a …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个扩展对象的函数,如:
{
'ab.cd.e' : 'foo',
'ab.cd.f' : 'bar',
'ab.g' : 'foo2'
}
Run Code Online (Sandbox Code Playgroud)
进入嵌套对象:
{ab: {cd: {e:'foo', f:'bar'}, g:'foo2'}}
Run Code Online (Sandbox Code Playgroud)
喜欢这个php函数:Set :: expand()
当然不使用eval.
我正在开发仅在Chrome上运行的应用程序.
我需要能够从播放视频切换源.
我用javascript(和jQuery)来改变src属性:
$fullscreenVideo.get(0).src = '/video/' + name + '.mp4'; // crash here
$fullscreenVideo.get(0).load();
$fullscreenVideo.get(0).play();
Run Code Online (Sandbox Code Playgroud)
它工作了几次,但我的chrome(尝试测试版和开发频道)最终崩溃(页面变得无法响应).
如果我尝试创建一个新元素,在前面的代码块前面加上:
$fullscreenVideo.remove();
$fullscreenVideo = $('<video id="video-fullscreen" width="800" height="600" loop="loop"></video>').appendTo("#page-fullscreen > div.fullscreen");
Run Code Online (Sandbox Code Playgroud)
每个视频开关都可以将RAM增加20Mo,而不会退缩.
有没有办法跟踪/防止Chrome崩溃和src更新?有没有办法强制释放内存?
我试图构建一个小功能,可以在控制器中使用,即时切换数据库,我必须只使用一个数据源.
在我的database.php上:
function __construct() {
$server = Configure::read('Server');
if(!empty($server['database'])) $this->local['database'] = $server['database'];
$this->default = $this->{$server['datasource']};
}
Run Code Online (Sandbox Code Playgroud)
用于根据服务器配置切换数据库.它工作得很好.
我试图建立这个:
/**
* Connects to specified database
*
* @param array $config Server config to use {datasource:?, database:?}
* @return array db->config on success, false on failure
* @access public
*/
function dbConnect($config = array()) {
ClassRegistry::init('ConnectionManager');
//debug($config['datasource']);
//$dbInstance =& ConnectionManager::getInstance();
//$dbInstance->config->{$config['datasource']}['database'] = $config['database'];
$db =& ConnectionManager::getDataSource($config['datasource']);
$db->disconnect();
$db->cacheSources = false;
$db->config['database'] = $config['database'];
$db->config['persistent'] = false;
debug($db->config);
$db->connect();
if(!$db->isConnected()) {
$this->error('!$db->isConnected()');
return …Run Code Online (Sandbox Code Playgroud) 我有一个包含firstName和lastName字段的MongoDB集合,我需要检索与特定fullNames匹配的项目:
是否有一种简单的方法来编写一个检查它的查询:
firstName + " " + lastName IN ARRAY ()... ?
Run Code Online (Sandbox Code Playgroud)
---编辑---
连接的原因是我不希望结果中的账单作业(考虑到它存在)如果我有[bill,steve]为firstName和[gate,jobs]作为姓氏.
谢谢!
我正在构建一个需要能够扩展facebook图形数据的应用程序.
我是NoSQL存储的新手,我正在寻求帮助.
使用图形api,我可以检索用户,因为我希望我的应用程序能够扩展几个社交图形提供程序,我将每个特定的facebook密钥移动到一个facebook数组子集中.
[User] => Array
(
[_id] => 4dd50c139bcb233c0c000000
[name] => Foo Bar
[first_name] => Foo
[last_name] => Bar
[username] => fbar
[location] => Array
(
[id] => 110774245616525
[name] => Paris, France
)
[gender] => male
[email] => fbar@gmail.com
[timezone] => 2
[locale] => fr_FR
[facebook] => Array
(
[id] => 12345678
[link] => http://www.facebook.com/foobar
[verified] => 1
[updated_time] => 2011-05-16T17:30:23+0000
[picture] => https://graph.facebook.com/12345678/picture
)
[created] => MongoDate Object
(
[sec] => 1305807891
[usec] => 0 …Run Code Online (Sandbox Code Playgroud) 我正在为iOS开发MDM NodeJS服务器.在Apple文档中,给出了以下ruby代码:
p7sign = OpenSSL::PKCS7::PKCS7.new(req.body)
store = OpenSSL::X509::Store.new
p7sign.verify(nil, store, nil, OpenSSL::PKCS7::NOVERIFY)
signers = p7sign.signers
Run Code Online (Sandbox Code Playgroud)
NodeJS中的等价物是什么?我们的想法是访问p7sign.data包含xml plist的内容.
是否可以使用其中一个crypto或外部节点lib(ursa等)?
$update = $col->update(array('_id' => 'test'), array('$push' => array('friends' => 1)), array('safe' => true, 'upsert' => true));
$test = $col->findOne(array('_id' => 'test'));
debug(compact('update', 'test'));
Run Code Online (Sandbox Code Playgroud)
不能按预期工作.
我得到(通过RockMongo检查):
{
"_id": "test",
"friends": {
"0": 1
}
}
Run Code Online (Sandbox Code Playgroud)
我希望/期望有这个:
{
"_id": "test",
"friends": [
1
]
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗 ?谢谢 !
mongodb ×5
node.js ×3
javascript ×2
mongoose ×2
php ×2
angularjs ×1
cakephp ×1
cakephp-1.3 ×1
cryptography ×1
database ×1
encryption ×1
facebook ×1
graph ×1
html5 ×1
html5-video ×1
ios ×1
nosql ×1
pkcs#7 ×1
validation ×1