MongoDB,在集合之间使用Mongodb ObjectID(MongoDB, Using Mongodb ObjectID between collections)
使用PHP和MongoDB,我有一个名为users的集合,另一个在同一个DB中称为表单。
我使用Mongodb ObjectID作为表单集合中文档的用户标识符,将用户ObjectId保存为每个表单文档上的uid。
我将在表单集合中创建一个uid字段的索引,但我的问题是我应该如何保存用户Objectid?
截至目前,我将其保存为普通字符串,如(简化)
$collection->insert( array('formName'=>'The name','uid'=>'CURRENT_USERS_ObjectId_AS_string') );
在这种情况下,这似乎是逻辑或最佳实践,为uid创建Mongodb ObjectID
$collection->insert( array('formName'=>'The name','uid'=> new MongoId('CURRENT_USERS_ObjectId_AS_string')) );
Using PHP and MongoDB, i have a collection called users and another one called forms in the same DB.
I am using the Mongodb ObjectID as user identifier for the documents in the forms collection, saving the users ObjectId as uid on each forms document.
I am going to create an index of the uid field in the forms collection, but my question is how i should save the users Objectid?
As of now I am saving it as a normal string like (simplified)
$collection->insert( array('formName'=>'The name','uid'=>'CURRENT_USERS_ObjectId_AS_string') );
Does this seem logic or is best practice in this case to create a Mongodb ObjectID for uid like
$collection->insert( array('formName'=>'The name','uid'=> new MongoId('CURRENT_USERS_ObjectId_AS_string')) );
原文:https://stackoverflow.com/questions/13068533
最满意答案
的标记
date-disabled="disabled(date, mode)"
意味着在你的作用域中你需要有一个名为
disabed
的函数,它接受两个参数,date
和mode
,你将用它来确定是否应该禁用该日期。这是一个更清晰的例子。 制作标记
date-disabled="shouldDateBeDisabled(date, mode)"
然后在你的Controller中你需要将一个名为
shouldDateBeDisabled
的函数shouldDateBeDisabled
到你将放置逻辑的$scope
。var datesAreEqual = function(date1,date2) {...}; var dateIsInArray = function(date,arrayOfDates) {...}; var someSingleDateToDisable = ...; var arrayOfDatesToDisable = [...]; $scope.shouldDateBeDisabled = function(date, mode) { // your own logic to determine if a date should be disabled if (datesAreEqual(date,someSingleDateToDisable) { return true; } if (dateIsInArray(date,arrayOfDatesToDisable) { return true; } return false; };
The markup of
date-disabled="disabled(date, mode)"
means that in your scope you would need to have a function named
disabed
that accepts two arguments,date
andmode
, which you would use to determine if that date should be disabled.Here is a clearer example for you. Make the markup be
date-disabled="shouldDateBeDisabled(date, mode)"
Then in your Controller you would need to attach a function named
shouldDateBeDisabled
to the$scope
where you would put your logic.var datesAreEqual = function(date1,date2) {...}; var dateIsInArray = function(date,arrayOfDates) {...}; var someSingleDateToDisable = ...; var arrayOfDatesToDisable = [...]; $scope.shouldDateBeDisabled = function(date, mode) { // your own logic to determine if a date should be disabled if (datesAreEqual(date,someSingleDateToDisable) { return true; } if (dateIsInArray(date,arrayOfDatesToDisable) { return true; } return false; };
相关问答
更多-
如果您正在使用DatePicker格式,则角色只能将本地化的js文件添加到页面的标题中。 一个例子是: