我正在运行Mongodb的2.06版本和10Gen提供的C#驱动程序的版本(1.5).
我的每个实体都有一个Id属性设置......
[BsonId(IdGenerator = typeof(GuidGenerator))]
public Guid Id { get; set; }
Run Code Online (Sandbox Code Playgroud)
Id字段存储为Binary - 3:UuidLegacy.因为我在实体上调用ToJson()时它是如何存储的,它会为Id返回以下javascript对象.
_id : Object
$binary: "some values here"
$type: "03"
Run Code Online (Sandbox Code Playgroud)
这显然是因为数据存储为Binary = 3:UuidLegacy.这是有道理的.
我想在我的Javascript代码中使用实际的Guid.如果我将我的Id属性看起来如下,那么它对MongoDB的效率如何?
[BsonId(IdGenerator = typeof(GuidGenerator)),MongoDB.Bson.Serialization.Attributes.BsonRepresentation(BsonType.String)]
public Guid Id { get; set; }
Run Code Online (Sandbox Code Playgroud)
这使得mongodb将我的Id存储为字符串.但这真的有多高效?我猜我的Id的二进制格式更好,但我真的需要Guid.
我如何从二进制 - 3:uuidLegacy转到我在json中需要的Guid?
我想另一个想法是我可以使用发送给我的$ binary值吗?我使用Id执行查找,例如我的查询字符串的一部分.
谢谢,
我正在使用官方MongoDB C#驱动程序的1.5.0.4566版.我正在使用Mongo 2.06版.
这是我的文档结构的样子(省略了本讨论不需要的字段):
{ "Parents" :
[
{
"CreatedOn": ISODate("2012-07-28T15:30:06.623Z"),
"Title": "Simple Title",
"Children": [
{ "StatusId": 1, "Active" : true, SubChild : { "ExpiresOn": ISODate("2012-07-28T15:30:06.623Z")}},
{ "StatusId": 1, "Active" : true, SubChild : { "ExpiresOn": ISODate("2012-08-28T15:30:06.623Z")}}
]
},
{
"CreatedOn": ISODate("2012-07-28T15:30:06.623Z"),
"Title": "Another Simple Title",
"Children": [
{ "StatusId": 1, "Active" : true, SubChild : { "ExpiresOn": ISODate("2012-07-28T15:30:06.623Z")}},
{ "StatusId": 1, "Active" : true, SubChild : { "ExpiresOn": ISODate("2012-08-28T15:30:06.623Z")}}
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
如果我想查询StatusId等于1并且Active为true的Children,我可以使用ElemMatch.
Query.ElemMatch("Children", Query.And(Query.EQ("StatusId", 1),Query.EQ("Active",true)));
Run Code Online (Sandbox Code Playgroud)
我无法工作的是当我需要在查询中包含SubChild元素时. …
背景: 我有一个Person域对象.它是一个聚合根.我已经在下面列出了一部分课程.
我正在公开执行对象行为的方法.例如,要添加BankAccount,我有AddBankAccount()方法.我没有包括该类的所有方法,但足以说必须使用方法更新任何公共属性.
我将创建一个IPerson存储库来处理CRUD操作.
public interface IPersonRepository
{
void Save(Person p);
//...other methods
}
Run Code Online (Sandbox Code Playgroud)
问题:在更新现有人员时,如何告知存储库需要更新哪些字段?例如,如果我向现有人员添加银行帐户,当调用repository.Save()时,如何将此信息传递给存储库?
在存储库中,很容易确定何时创建新人,但是当存在现有人员并且您更新该人员的字段时,我不确定如何将其传达给存储库.
我不想用有关哪些字段更新的信息污染我的Person对象.
我可以在存储库上有单独的方法,如.UpdateEmail(),AddBankAccount(),但这感觉有点矫枉过正.我想在存储库上使用一个简单的.Save()方法,它确定需要以某种方式更新的内容.
别人怎么处理这种情况?
我搜索了网络和stackoverflow但没有找到任何东西.我一定不能正确搜索,因为在DDD范例中持久化时,这似乎很简单.我也可以对DDD有所了解:-)
public class Person : DomainObject
{
public Person(int Id, string FirstName, string LastName,
string Name, string Email)
{
this.Id = Id;
this.CreditCards = new List<CreditCard>();
this.BankAccounts = new List<BankAccount>();
this.PhoneNumbers = new List<PhoneNumber>();
this.Sponsorships = new List<Sponsorship>();
}
public string FirstName { get; private set; }
public string LastName { get; private set; }
public string Name{ get; private …
Run Code Online (Sandbox Code Playgroud) domain-driven-design ddd-repositories aggregateroot repository-pattern
google recaptcha 创建了一个没有可访问性属性的 textarea,例如 aria-label。这导致 recaptcha 无法通过 Siteimprove 进行可访问性扫描。
我已经尝试使用 javascript 将 aria-label 属性添加到 textarea,但是我在将它添加到 DOM 后将它添加到元素中,所以我猜这就是可访问性失败的原因。
这是来自 Siteimproves google extension 的文本:
未通过的要求 4.1.2
textarea
为空。这是因为没有标签与文本区域相关联,或者 aria-label 属性未添加到文本区域。
我对以下演示有疑问 - http://raphaeljs.com/hand.html.
这是样本中的代码......
var r = Raphael("holder", 640, 480), angle = 0;
while (angle < 360) {
var color = Raphael.getColor();
(function(t, c) {
r.circle(320, 450, 20).attr({
stroke : c,
fill : c,
transform : t,
"fill-opacity" : .4
}).click(function() {
s.animate({
transform : t,
stroke : c
}, 2000, "bounce");
}).mouseover(function() {
this.animate({
"fill-opacity" : .75
}, 500);
}).mouseout(function() {
this.animate({
"fill-opacity" : .4
}, 500);
});
})("r" + angle + " 320 240", color);
angle += …
Run Code Online (Sandbox Code Playgroud) 我将电子邮件权限添加到我的Auth Dialog的"用户和朋友权限"中.
不幸的是,当我的用户授权我的应用程序时,它不会请求此权限.
Auth Dialog只是请求基本信息.
有趣的是,当我预览Auth对话框时,它会显示它请求电子邮件权限.
还有其他人有这个问题吗?
谢谢,
问题
我想调用 JSON.stringify 传递我想要包含在字符串中的字段。我想要包含的字段之一是一个对象。正如我所期望的那样,JSON.stringify 方法不包含对象中的任何字段。
这是我的较大对象的一小部分;
var person = {
name: "John Doe",
Address: { Line1: "100 north main", City: "Des Moines" },
Phone: "555-5555"
}
Run Code Online (Sandbox Code Playgroud)
这是 stringify 方法调用
console.log(JSON.stringify(person,["name","Address"]));
Run Code Online (Sandbox Code Playgroud)
这是结果
"{\"name\":\"John Doe\",\"Address\":{}}"
Run Code Online (Sandbox Code Playgroud)
这是我创建的 js bin - http://jsbin.com/UYOVufa/1/edit?html,console。
我总是可以只对 person.Address 进行字符串化,并将其与另一个字符串组合起来,但这感觉有点矫枉过正。
我缺少什么?
谢谢,