我知道这可能很简单,但似乎无法找到我正在尝试做的事情的例子。
从字符串的开头匹配,我想匹配建筑物编号。
IE
60 将匹配 60A 和 60 但不匹配 6000
同样地
1 将匹配 1 和 1ABC 但不匹配 11
/^1[^\0-9]*
就像我需要的那样,匹配 1 和任何非数值任意次数。(当然这是来自 expresso - (.net) 但它在那里不起作用。
有人能指出我正确的方向吗?
谢谢,
山姆
我正在使用MongoDB来保存一组文档.
每个文档都有一个_id(版本),它是一个ObjectId.每个文档都有一个documentId,它在不同版本之间共享.这也是在创建第一个文档时分配的OjectId.
在给出documentId的情况下,找到最新版本文档的最有效方法是什么?
即我想得到_id = max(_id)和documentId = x的记录
我需要使用MapReduce吗?
提前致谢,
山姆
我正在将我的代码转移到新的 2.0 驱动程序,并且遇到了 ObjectIds 问题。
以前,我使用 BsonId 和 BsonRepresentation 属性装饰了字符串 Id 属性。
现在我正在使用类映射
BsonClassMap.RegisterClassMap<Model>(cm =>
{
cm.MapIdMember(p => p.Id).SetIdGenerator(StringObjectIdGenerator.Instance);
cm.SetIgnoreExtraElements(true);
cm.AutoMap();
});
Run Code Online (Sandbox Code Playgroud)
在这个例子中模型非常简单
public class Model
{
public string Id { get; set; }
public DateTime UpdatedTs { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
但是插入后,我将对象 id 作为字符串返回,但它也是服务器上的字符串。
有什么我想念的吗?
谢谢山姆
我有一些类,我喜欢链式方法,以提供流畅的配置风格.
例如
public class BaseFoo
{
private bool _myProp = false;
public [[[BaseFoo?]]] SetMyProperty()
{
this._myProp = true;
return this;
}
}
public class DerivedFoo : BaseFoo
{
public bool _derivedProp = false;
public DerivedFoo SetDerivedPropery()
{
this._derivedProp = true;
return this;
}
}
Run Code Online (Sandbox Code Playgroud)
当我使用base方法返回BaseFoo类型时,问题显然是在尝试将它们链接在一起时.显然我可以将它转换回DerivedFoo,但是有一种简单的方法可以返回派生类类型的对象.
我能想到的唯一方法就是将构造函数链接在一起并将父类型传递给初始构造函数,但需要使用语法.
另一种方法是为每个子类提供类似的代理方法,但返回派生类型.
DerivedFoo foo = new DerivedFoo();
foo.SetMyProperty().SetDerivedPropery(); // wont work because the SetMyProperty returns type of BaseFoo
foo.SetDerivedPropery().SetMyProperty(); // works because I know i'm calling the method of the derived class first
(foo.SetMyProperty() as …Run Code Online (Sandbox Code Playgroud)