本文整理汇总了C#中BSONDocument类的典型用法代码示例。如果您正苦于以下问题:C# BSONDocument类的具体用法?C# BSONDocument怎么用?C# BSONDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BSONDocument类属于命名空间,在下文中一共展示了BSONDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateEntry
public UpdateEntry(BSONDocument query, BSONDocument update, bool multi, bool upsert)
{
Query = query;
Update = update;
Multi = multi;
Upsert = upsert;
}
示例2: btnCreateIndex_Click
private void btnCreateIndex_Click(object sender, EventArgs e)
{
var db = MongoClient.Instance.DefaultLocalServer["db1"];
var idx = new BSONDocument(@"
{
createIndexes: 't1',
indexes: [
{
key: {name: 1},
name: 'idxT1_Name',
unique: false
},
{
key: {age: -11},
name: 'idxT1_Age',
unique: false
}
]
}
",false);
MessageBox.Show( db.RunCommand( idx ).ToString() );
}
示例3: InferSchema
public void InferSchema()
{
var doc = new BSONDocument();
doc.Set( new BSONStringElement("FullName", "Alex Bobby") );
doc.Set( new BSONInt32Element("Age", 123) );
doc.Set( new BSONBooleanElement("IsGood", true) );
var c = new RowConverter();
var schema = c.InferSchemaFromBSONDocument(doc);
Assert.AreEqual(3, schema.FieldCount);
Assert.AreEqual(0, schema["FullName"].Order);
Assert.AreEqual(1, schema["Age"].Order);
Assert.AreEqual(2, schema["IsGood"].Order);
Assert.AreEqual(typeof(object), schema["FullName"].NonNullableType);
Assert.AreEqual(typeof(object), schema["Age"].NonNullableType);
Assert.AreEqual(typeof(object), schema["IsGood"].NonNullableType);
var row = new DynamicRow(schema);
c.BSONDocumentToRow(doc, row, null);
Assert.AreEqual("Alex Bobby", row[0]);
Assert.AreEqual(123, row[1]);
Assert.AreEqual(true, row[2]);
Assert.AreEqual("Alex Bobby", row["FullName"]);
Assert.AreEqual(123, row["Age"]);
Assert.AreEqual(true, row["IsGood"]);
}
示例4: TestFilteredDoc
public void TestFilteredDoc()
{
var doc = new BSONDocument();
doc["c"] = "d";
doc["aaa"] = 11;
doc["ndoc"] = BSONDocument.ValueOf(new {
aaaa = "nv1",
d = "nv2",
nnd = BSONDocument.ValueOf(new {
nnv = true,
nns = "s"
})
});
doc["ndoc2"] = BSONDocument.ValueOf(new {
n = "v"
});
doc["f"] = "f";
BSONIterator it = new BSONIterator(doc);
BSONDocument doc2 = it.ToBSONDocument("c", "ndoc.d", "ndoc.nnd.nns", "f");
Assert.AreEqual(3, doc2.KeysCount);
Assert.AreEqual("d", doc2["c"]);
Assert.AreEqual(2, ((BSONDocument) doc2["ndoc"]).KeysCount);
Assert.AreEqual("nv2", ((BSONDocument) doc2["ndoc"])["d"]);
Assert.AreEqual("s", ((BSONDocument) ((BSONDocument) doc2["ndoc"])["nnd"])["nns"]);
Assert.AreEqual("s", doc2["ndoc.nnd.nns"]);
Assert.AreEqual("f", "f");
//Console.WriteLine("doc2=" + doc2);
}
示例5: Test3SaveLoad
public void Test3SaveLoad()
{
EJDB jb = new EJDB("testdb1", EJDB.DEFAULT_OPEN_MODE | EJDB.JBOTRUNC);
Assert.IsTrue(jb.IsOpen);
BSONDocument doc = new BSONDocument().SetNumber("age", 33);
Assert.IsNull(doc["_id"]);
bool rv = jb.Save("mycoll", doc);
Assert.IsTrue(rv);
Assert.IsNotNull(doc["_id"]);
Assert.IsInstanceOf(typeof(BSONOid), doc["_id"]);
rv = jb.Save("mycoll", doc);
Assert.IsTrue(rv);
BSONIterator it = jb.Load("mycoll", doc["_id"] as BSONOid);
Assert.IsNotNull(it);
BSONDocument doc2 = it.ToBSONDocument();
Assert.AreEqual(doc.ToDebugDataString(), doc2.ToDebugDataString());
Assert.IsTrue(doc == doc2);
Assert.AreEqual(1, jb.CreateQueryFor("mycoll").Count());
Assert.IsTrue(jb.Remove("mycoll", doc["_id"] as BSONOid));
Assert.AreEqual(0, jb.CreateQueryFor("mycoll").Count());
jb.Save("mycoll", doc);
Assert.AreEqual(1, jb.CreateQueryFor("mycoll").Count());
Assert.IsTrue(jb.DropCollection("mycoll"));
Assert.AreEqual(0, jb.CreateQueryFor("mycoll").Count());
Assert.IsTrue(jb.Sync());
jb.Dispose();
}
示例6: EJDBQuery
internal EJDBQuery(EJDB jb, BSONDocument qdoc, string defaultcollection = null)
{
_qptr = _ejdbcreatequery(jb.DBPtr, qdoc.ToByteArray());
if (_qptr == IntPtr.Zero) {
throw new EJDBQueryException(jb);
}
_jb = jb;
_defaultcollection = defaultcollection;
}
示例7: WriteBigIntegers
public void WriteBigIntegers(Stream stream)
{
stream.Position = 0;
var root = new BSONDocument();
root.Set(new BSONInt32Element("intMin", int.MinValue));
root.Set(new BSONInt32Element("intMax", int.MaxValue));
root.Set(new BSONInt64Element("longMin", long.MinValue));
root.Set(new BSONInt64Element("longMax", long.MaxValue));
root.WriteAsBSON(stream);
}
示例8: ReadEmptyDocument
public void ReadEmptyDocument()
{
var src = Convert.FromBase64String(@"BQAAAAA=");
using (var stream = new MemoryStream(src))
{
var root = new BSONDocument(stream);
Assert.AreEqual(root.ByteSize, 5);
Assert.AreEqual(root.Count, 0);
Assert.AreEqual(stream.Position, 5); // ensure whole document readed
}
}
示例9: FindOne
/// <summary>
/// Finds a document that satisfied query or null
/// </summary>
public BSONDocument FindOne(Query query, BSONDocument selector = null)
{
EnsureObjectNotDisposed();
if (query==null)
throw new MongoDBConnectorException(StringConsts.ARGUMENT_ERROR+"Collection.FindOne(query==null)");
var connection = Server.AcquireConnection();
try
{
var reqId = Database.NextRequestID;
return connection.FindOne(reqId, this, query, selector);
}
finally
{
connection.Release();
}
}
示例10: CollectionDrop
public void CollectionDrop()
{
using(var client= new MongoClient("My Test"))
{
var collection = client.DefaultLocalServer["db1"]["ToDrop"];
var doc1 = new BSONDocument();
doc1.Set( new BSONStringElement("_id", "id1"))
.Set( new BSONStringElement("val", "My value"))
.Set( new BSONInt32Element("age", 125));
var r = collection.Insert(doc1);
Assert.AreEqual(1, r.TotalDocumentsAffected);
collection.Drop();
Assert.IsTrue( collection.Disposed );
}
}
示例11: ReadBigIntegers
public void ReadBigIntegers()
{
var src = Convert.FromBase64String(@"PwAAABBpbnRNaW4AAAAAgBBpbnRNYXgA////fxJsb25nTWluAAAAAAAAAACAEmxvbmdNYXgA/////////38A");
using (var stream = new MemoryStream(src))
{
var root = new BSONDocument(stream);
Assert.AreEqual(root.ByteSize, 63);
Assert.AreEqual(root.Count, 4);
var element1 = root["intMin"] as BSONInt32Element;
Assert.IsNotNull(element1);
Assert.AreEqual(element1.ElementType, BSONElementType.Int32);
Assert.AreEqual(element1.Name, "intMin");
Assert.AreEqual(element1.Value, int.MinValue);
var element2 = root["intMax"] as BSONInt32Element;
Assert.IsNotNull(element2);
Assert.AreEqual(element2.ElementType, BSONElementType.Int32);
Assert.AreEqual(element2.Name, "intMax");
Assert.AreEqual(element2.Value, int.MaxValue);
var element3 = root["longMin"] as BSONInt64Element;
Assert.IsNotNull(element3);
Assert.AreEqual(element3.ElementType, BSONElementType.Int64);
Assert.AreEqual(element3.Name, "longMin");
Assert.AreEqual(element3.Value, long.MinValue);
var element4 = root["longMax"] as BSONInt64Element;
Assert.IsNotNull(element4);
Assert.AreEqual(element4.ElementType, BSONElementType.Int64);
Assert.AreEqual(element4.Name, "longMax");
Assert.AreEqual(element4.Value, long.MaxValue);
Assert.AreEqual(stream.Position, 63); // ensure whole document readed
}
}
示例12: ReadUnicodeStrings
public void ReadUnicodeStrings()
{
var src = Convert.FromBase64String(@"6AAAAAJlbmcABgAAAGhlbGxvAAJydXMADQAAANC/0YDQuNCy0LXRggACY2hpAAcAAADkvaDlpb0AAmphcAAQAAAA44GT44KT44Gr44Gh44GvAAJncmUAEAAAAM6zzrXOuc6xIM+DzrHPggACYWxiAA8AAABww6tyc2jDq25kZXRqZQACYXJtABIAAADVotWh1oDVpdaCINWB1aXVpgACdmllAAoAAAB4aW4gY2jDoG8AAnBvcgAFAAAAT2zDoQACdWtyAA0AAADQn9GA0LjQstGW0YIAAmdlcgAJAAAAd8O8bnNjaGUAAA==");
using (var stream = new MemoryStream(src))
{
var root = new BSONDocument(stream);
Assert.AreEqual(root.ByteSize, 232);
Assert.AreEqual(root.Count, 11);
var element = root["eng"] as BSONStringElement;
Assert.IsNotNull(element);
Assert.AreEqual(element.ElementType, BSONElementType.String);
Assert.AreEqual(element.Name, "eng");
Assert.AreEqual(element.Value, "hello");
element = root["rus"] as BSONStringElement;
Assert.IsNotNull(element);
Assert.AreEqual(element.ElementType, BSONElementType.String);
Assert.AreEqual(element.Name, "rus");
Assert.AreEqual(element.Value, "привет");
element = root["chi"] as BSONStringElement;
Assert.IsNotNull(element);
Assert.AreEqual(element.ElementType, BSONElementType.String);
Assert.AreEqual(element.Name, "chi");
Assert.AreEqual(element.Value, "你好");
element = root["jap"] as BSONStringElement;
Assert.IsNotNull(element);
Assert.AreEqual(element.ElementType, BSONElementType.String);
Assert.AreEqual(element.Name, "jap");
Assert.AreEqual(element.Value, "こんにちは");
element = root["gre"] as BSONStringElement;
Assert.IsNotNull(element);
Assert.AreEqual(element.ElementType, BSONElementType.String);
Assert.AreEqual(element.Name, "gre");
Assert.AreEqual(element.Value, "γεια σας");
element = root["alb"] as BSONStringElement;
Assert.IsNotNull(element);
Assert.AreEqual(element.ElementType, BSONElementType.String);
Assert.AreEqual(element.Name, "alb");
Assert.AreEqual(element.Value, "përshëndetje");
element = root["arm"] as BSONStringElement;
Assert.IsNotNull(element);
Assert.AreEqual(element.ElementType, BSONElementType.String);
Assert.AreEqual(element.Name, "arm");
Assert.AreEqual(element.Value, "բարեւ Ձեզ");
element = root["vie"] as BSONStringElement;
Assert.IsNotNull(element);
Assert.AreEqual(element.ElementType, BSONElementType.String);
Assert.AreEqual(element.Name, "vie");
Assert.AreEqual(element.Value, "xin chào");
element = root["por"] as BSONStringElement;
Assert.IsNotNull(element);
Assert.AreEqual(element.ElementType, BSONElementType.String);
Assert.AreEqual(element.Name, "por");
Assert.AreEqual(element.Value, "Olá");
element = root["ukr"] as BSONStringElement;
Assert.IsNotNull(element);
Assert.AreEqual(element.ElementType, BSONElementType.String);
Assert.AreEqual(element.Name, "ukr");
Assert.AreEqual(element.Value, "Привіт");
element = root["ger"] as BSONStringElement;
Assert.IsNotNull(element);
Assert.AreEqual(element.ElementType, BSONElementType.String);
Assert.AreEqual(element.Name, "ger");
Assert.AreEqual(element.Value, "wünsche");
Assert.AreEqual(stream.Position, 232); // ensure whole document readed
}
}
示例13: Templatization_ArrayOfUnicodeStringNames
public void Templatization_ArrayOfUnicodeStringNames()
{
var qry0 = new BSONDocument("{ '$$eng': 'eng', '$$rus': 'rus', '$$chi': 'chi', '$$jap': 'jap', '$$gre': 'gre', '$$alb': 'alb', '$$arm': 'arm', '$$vie': 'vie', '$$por': 'por', '$$ukr': 'ukr', '$$ger': 'ger' }", true,
new TemplateArg("eng", BSONElementType.String, "hello"),
new TemplateArg("rus", BSONElementType.String, "привет"),
new TemplateArg("chi", BSONElementType.String, "你好"),
new TemplateArg("jap", BSONElementType.String, "こんにちは"),
new TemplateArg("gre", BSONElementType.String, "γεια σας"),
new TemplateArg("alb", BSONElementType.String, "përshëndetje"),
new TemplateArg("arm", BSONElementType.String, "բարեւ Ձեզ"),
new TemplateArg("vie", BSONElementType.String, "xin chào"),
new TemplateArg("por", BSONElementType.String, "Olá"),
new TemplateArg("ukr", BSONElementType.String, "Привіт"),
new TemplateArg("ger", BSONElementType.String, "wünsche"));
Assert.AreEqual(qry0.Count, 11);
Assert.IsNotNull(qry0["hello"]);
Assert.IsInstanceOf<BSONStringElement>(qry0["hello"]);
Assert.AreEqual(((BSONStringElement)qry0["hello"]).Value, "eng");
Assert.IsNotNull(qry0["привет"]);
Assert.IsInstanceOf<BSONStringElement>(qry0["привет"]);
Assert.AreEqual(((BSONStringElement)qry0["привет"]).Value, "rus");
Assert.IsNotNull(qry0["你好"]);
Assert.IsInstanceOf<BSONStringElement>(qry0["你好"]);
Assert.AreEqual(((BSONStringElement)qry0["你好"]).Value, "chi");
Assert.IsNotNull(qry0["こんにちは"]);
Assert.IsInstanceOf<BSONStringElement>(qry0["こんにちは"]);
Assert.AreEqual(((BSONStringElement)qry0["こんにちは"]).Value, "jap");
Assert.IsNotNull(qry0["γεια σας"]);
Assert.IsInstanceOf<BSONStringElement>(qry0["γεια σας"]);
Assert.AreEqual(((BSONStringElement)qry0["γεια σας"]).Value, "gre");
Assert.IsNotNull(qry0["përshëndetje"]);
Assert.IsInstanceOf<BSONStringElement>(qry0["përshëndetje"]);
Assert.AreEqual(((BSONStringElement)qry0["përshëndetje"]).Value, "alb");
Assert.IsNotNull(qry0["բարեւ Ձեզ"]);
Assert.IsInstanceOf<BSONStringElement>(qry0["բարեւ Ձեզ"]);
Assert.AreEqual(((BSONStringElement)qry0["բարեւ Ձեզ"]).Value, "arm");
Assert.IsNotNull(qry0["xin chào"]);
Assert.IsInstanceOf<BSONStringElement>(qry0["xin chào"]);
Assert.AreEqual(((BSONStringElement)qry0["xin chào"]).Value, "vie");
Assert.IsNotNull(qry0["Olá"]);
Assert.IsInstanceOf<BSONStringElement>(qry0["Olá"]);
Assert.AreEqual(((BSONStringElement)qry0["Olá"]).Value, "por");
Assert.IsNotNull(qry0["Привіт"]);
Assert.IsInstanceOf<BSONStringElement>(qry0["Привіт"]);
Assert.AreEqual(((BSONStringElement)qry0["Привіт"]).Value, "ukr");
Assert.IsNotNull(qry0["wünsche"]);
Assert.IsInstanceOf<BSONStringElement>(qry0["wünsche"]);
Assert.AreEqual(((BSONStringElement)qry0["wünsche"]).Value, "ger");
}
示例14: Templatization_ArrayOfUnicodeStringValues
public void Templatization_ArrayOfUnicodeStringValues()
{
var qry0 = new BSONDocument("{ '$$unicode': [ '$$eng', '$$rus', '$$chi', '$$jap', '$$gre', '$$alb', '$$arm', '$$vie', '$$por', '$$ukr', '$$ger' ] }", true,
new TemplateArg("unicode", BSONElementType.String, "strings"),
new TemplateArg("eng", BSONElementType.String, "hello"),
new TemplateArg("rus", BSONElementType.String, "привет"),
new TemplateArg("chi", BSONElementType.String, "你好"),
new TemplateArg("jap", BSONElementType.String, "こんにちは"),
new TemplateArg("gre", BSONElementType.String, "γεια σας"),
new TemplateArg("alb", BSONElementType.String, "përshëndetje"),
new TemplateArg("arm", BSONElementType.String, "բարեւ Ձեզ"),
new TemplateArg("vie", BSONElementType.String, "xin chào"),
new TemplateArg("por", BSONElementType.String, "Olá"),
new TemplateArg("ukr", BSONElementType.String, "Привіт"),
new TemplateArg("ger", BSONElementType.String, "wünsche"));
Assert.AreEqual(qry0.Count, 1);
Assert.IsNotNull(qry0["strings"]);
Assert.IsInstanceOf<BSONArrayElement>(qry0["strings"]);
var array = ((BSONArrayElement)qry0["strings"]).Value;
Assert.IsNotNull(array);
Assert.AreEqual(array.Length, 11);
Assert.AreEqual(((BSONStringElement)array[0]).Value, "hello");
Assert.AreEqual(((BSONStringElement)array[1]).Value, "привет");
Assert.AreEqual(((BSONStringElement)array[2]).Value, "你好");
Assert.AreEqual(((BSONStringElement)array[3]).Value, "こんにちは");
Assert.AreEqual(((BSONStringElement)array[4]).Value, "γεια σας");
Assert.AreEqual(((BSONStringElement)array[5]).Value, "përshëndetje");
Assert.AreEqual(((BSONStringElement)array[6]).Value, "բարեւ Ձեզ");
Assert.AreEqual(((BSONStringElement)array[7]).Value, "xin chào");
Assert.AreEqual(((BSONStringElement)array[8]).Value, "Olá");
Assert.AreEqual(((BSONStringElement)array[9]).Value, "Привіт");
Assert.AreEqual(((BSONStringElement)array[10]).Value, "wünsche");
}
示例15: Templatization_QueryComplexObject
public void Templatization_QueryComplexObject()
{
var qry0 = new BSONDocument(
"{" +
"'$$item1': 23," +
"item2: [1, '$$item21', 123.456], " +
"'$$item3': { item31: '$$false', item32: '$$array', item33: {} }," +
"'$$item4': {" +
"'$$item41': [1, 2, 3]," +
"'$$item42': false," +
"item43: '$$double'," +
"item44: 'こんこんвапаъü'," +
"item45: { item451: '$$array2', item452: true, item453: {} }" +
"} "+
"}", true,
new TemplateArg("item1", BSONElementType.String, "item1"),
new TemplateArg("item21", BSONElementType.String, "こん好արüвіт"),
new TemplateArg("item3", BSONElementType.String, "item3"),
new TemplateArg("false", BSONElementType.Boolean, false),
new TemplateArg("array", BSONElementType.Array,
new BSONElement[]
{
new BSONBooleanElement(true),
new BSONBooleanElement(true),
new BSONBooleanElement(false)
}),
new TemplateArg("item4", BSONElementType.String, "item4"),
new TemplateArg("item41", BSONElementType.String, "item41"),
new TemplateArg("item42", BSONElementType.String, "item42"),
new TemplateArg("double", BSONElementType.Double, -123.4567),
new TemplateArg("array2", BSONElementType.Array,
new BSONElement[]
{
new BSONInt64Element(2),
})
);
Assert.AreEqual(qry0.Count, 4);
Assert.AreEqual(((BSONInt32Element)qry0["item1"]).Value, 23);
var item2 = ((BSONArrayElement)qry0["item2"]).Value;
Assert.AreEqual(item2.Length, 3);
Assert.AreEqual(((BSONInt32Element)item2[0]).Value, 1);
Assert.AreEqual(((BSONStringElement)item2[1]).Value, "こん好արüвіт");
Assert.AreEqual(((BSONDoubleElement)item2[2]).Value, 123.456D);
var item3 = ((BSONDocumentElement)qry0["item3"]).Value;
Assert.AreEqual(item3.Count, 3);
Assert.AreEqual(((BSONBooleanElement)item3["item31"]).Value, false);
var arr = ((BSONArrayElement)item3["item32"]).Value;
Assert.AreEqual(arr.Length, 3);
Assert.AreEqual(((BSONBooleanElement)arr[0]).Value, true);
Assert.AreEqual(((BSONBooleanElement)arr[1]).Value, true);
Assert.AreEqual(((BSONBooleanElement)arr[2]).Value, false);
var item33 = ((BSONDocumentElement)item3["item33"]).Value;
Assert.AreEqual(item33.Count, 0);
var item4 = ((BSONDocumentElement)qry0["item4"]).Value;
Assert.AreEqual(item4.Count, 5);
var item41 = ((BSONArrayElement)item4["item41"]).Value;
Assert.AreEqual(item41.Length, 3);
Assert.AreEqual(((BSONInt32Element)item41[0]).Value, 1);
Assert.AreEqual(((BSONInt32Element)item41[1]).Value, 2);
Assert.AreEqual(((BSONInt32Element)item41[2]).Value, 3);
Assert.AreEqual(((BSONBooleanElement)item4["item42"]).Value, false);
Assert.AreEqual(((BSONDoubleElement)item4["item43"]).Value, -123.4567D);
Assert.AreEqual(((BSONStringElement)item4["item44"]).Value, "こんこんвапаъü");
var item45 = ((BSONDocumentElement)item4["item45"]).Value;
Assert.AreEqual(item45.Count, 3);
var item451 = ((BSONArrayElement)item45["item451"]).Value;
Assert.AreEqual(item451.Length, 1);
Assert.AreEqual(((BSONInt64Element)item451[0]).Value, 2);
Assert.AreEqual(((BSONBooleanElement)item45["item452"]).Value, true);
var item453 = ((BSONDocumentElement)item45["item453"]).Value;
Assert.AreEqual(item453.Count, 0);
}