本文整理汇总了C#中BsonDocument.Add方法的典型用法代码示例。如果您正苦于以下问题:C# BsonDocument.Add方法的具体用法?C# BsonDocument.Add怎么用?C# BsonDocument.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BsonDocument
的用法示例。
在下文中一共展示了BsonDocument.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
//连接信息
string conn = "mongodb://localhost";
string database = "demoBase";
string collection = "demoCollection";
MongoServer mongodb = MongoServer.Create(conn);
//连接数据库
MongoDatabase mongoDataBase = mongodb.GetDatabase(database);
//选择数据库名
MongoCollection mongoCollection = mongoDataBase.GetCollection(collection);
//选择集合,相当于表
mongodb.Connect();
//普通插入
var o = new { Uid = 123, Name = "xixiNormal", PassWord = "111111" };
mongoCollection.Insert(o);
//对象插入
Person p = new Person { Uid = 124, Name = "xixiObject", PassWord = "222222" };
mongoCollection.Insert(p);
//BsonDocument 插入
BsonDocument b = new BsonDocument();
b.Add("Uid", 125);
b.Add("Name", "xixiBson");
b.Add("PassWord", "333333");
mongoCollection.Insert(b);
Console.WriteLine(mongoCollection.FullName);
QueryDocument query = new QueryDocument();
query.Add("Uid", 125);
MongoCursor<Person> pers = mongoCollection.FindAs<Person>(query);
//Console.WriteLine(pe.Name);
Console.ReadLine();
}
示例2: GetDatingBookUserInfo
public DatingBookUserInfo GetDatingBookUserInfo(string appName, ObjectId userId)
{
var datingBookUserInfo = _userDataProvider.GetDatingBookUserInfoByFacebookId(appName, userId);
if (datingBookUserInfo == null)
return null;
if (!CheckIfUserPictureExist(appName, datingBookUserInfo))
DownloadUserPicture(appName, datingBookUserInfo);
datingBookUserInfo.LastVisit = DateTime.Now;
ObjectId visitId = ObjectId.Empty;
var whiteList = _userDataProvider.GetUsersWhitelist(appName);
if (!whiteList.Exists((usr) => usr == datingBookUserInfo.FacebookId))
{
BsonDocument visit = new BsonDocument();
visit.Add("dating_book_id", datingBookUserInfo.ObjectId);
visit.Add("entered_at", datingBookUserInfo.LastVisit);
visitId = _userDataProvider.InsertVisit(appName, visit);
}
datingBookUserInfo = _userDataProvider.UpdateDatingBookLastVisit(appName, datingBookUserInfo, visitId);
var userEventInfo = new UserEventInfo
{
UserId = datingBookUserInfo.ObjectId,
EventType = 1,
DateCreated = DateTime.Now
};
_userDataProvider.InsertUserEvent(appName, userEventInfo);
return datingBookUserInfo;
}
示例3: parseNumericElements
/// <summary>
/// Converts all numeric BsonElement values from string represenjtation to numeric values (Int32/Double), i.e. {"id":"1"} => {"id":1}
/// </summary>
public static BsonDocument parseNumericElements(this BsonDocument original)
{
var result = new BsonDocument();
Int32 numInt32;
Int64 numInt64;
double numDouble;
foreach(var el in original)
{
string elValue = el.Value.ToString();
if (elValue.Contains('.') && Double.TryParse(elValue, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out numDouble))
{
result.Add(el.Name, numDouble);
}
else if(Int32.TryParse(elValue, out numInt32))
{
result.Add(el.Name, numInt32);
}
else if (Int64.TryParse(elValue, out numInt64))
{
result.Add(el.Name, numInt64);
}
else
{
result.Add(el);
}
}
return result;
}
示例4: btn_start_Click
private void btn_start_Click(object sender, EventArgs e)
{
//线程更新窗体内容
_thread = new Thread(new ThreadStart(set_txt));
_thread.Start();
//线程传递参数
ParameterizedThreadStart start = new ParameterizedThreadStart(set_txt);
Thread thread = new Thread(start);
object obj = "From Thread With Pareameter:Hello ParameterizedThreadStart!!! ";
thread.Start(obj);
Thread thread2 = new Thread(() => set_txt("From Thread With Lambda:Hello Lam!!!"));
thread2.Start();
ThreadPool.SetMaxThreads(100, 50);
ThreadPool.QueueUserWorkItem(set_txt, "From Thread With ThreadPool:Hello ThreadPool!!!");
//传递BsonDocument
BsonDocument doc_input = new BsonDocument();
doc_input.Add("sleep", 700);
doc_input.Add("txt", "From BsonDocument!!!");
ParameterizedThreadStart start3 = new ParameterizedThreadStart(set_txt_with_doc);
Thread thread3 = new Thread(start3);
object obj3 = (object)doc_input;
thread3.Start(obj3);
//异步调用
D_Add handler = new D_Add(f_add);
sb.AppendLine("Start Add!!");
IAsyncResult result = handler.BeginInvoke(1, 2, new AsyncCallback(f_complete), "AsycState:OK");
sb.AppendLine("Start do other work!!");
this.txt_result.Text = sb.ToString();
}
示例5: Main
static void Main(string[] args)
{
var server = MongoServer.Create("mongodb://localhost");
MongoDatabase test = server.GetDatabase("test");
MongoCredentials credentials = new MongoCredentials("username", "password");
MongoDatabase salaries = server.GetDatabase("salaries", credentials);
MongoCollection docs = test.GetCollection("docs");
docs.EnsureIndex("title");
Console.WriteLine("adding some test documents");
for (int x = 0; x < 1000; x++) {
BsonDocument doc = new BsonDocument();
doc.Add("title", "title: " + x);
doc.Add("body", "body: " + x);
docs.Insert(doc);
}
Console.WriteLine("querying");
foreach (var doc in docs.FindAllAs<BsonDocument>()) {
Console.WriteLine("doc: {0}", doc["body"]);
}
}
示例6: ToBsonDocument
public static BsonDocument ToBsonDocument(this XElement xElement)
{
var bsonDocument = new BsonDocument();
var type = xElement.Name.ToString();
bsonDocument.Add(Constants._TYPE, type);
var mainId = xElement.Attribute(Constants._ID) != null ? xElement.Attribute(Constants._ID).Value : null;
foreach (XAttribute attribure in xElement.Attributes())
{
var key = attribure.Name.ToString();
var value = attribure.Value;
if (bsonDocument.Contains(key))
bsonDocument.Set(key, value);
else
bsonDocument.Add(key, value);
}
foreach (XElement kid in xElement.Descendants())
{
var id = kid.Attribute(Constants._ID);
if (id == null || mainId == null)
{
bsonDocument.Add(kid.Name.ToString(), kid.ToBsonDocument());
}
else
{
kid.SetAttributeValue(Constants.PARENT_ID, mainId);
DBFactory.GetData().Save(kid);
}
}
return bsonDocument;
}
示例7: RemoveMark
/// <summary>
/// 删除标记
/// </summary>
/// <param name="Data">删除条件</param>
/// <param name="ReceiveMessage">回调消息</param>
public void RemoveMark(BsonDocument Data, BsonDocument ReceiveMessage)
{
Data.Add("ForCase", CaseInfo.CaseName);
if (mm.RemoveMark(Data.GetValue("MarkName").AsString))
{
if (ms.RemoveMark(Data).IsAcknowledged)
{
ReceiveMessage.Add("StateCode", 0);
ReceiveMessage.Add("ReData", "标记已删除!");
CallBack();
}
else
{
ReceiveMessage.Add("StateCode", -1);
ReceiveMessage.Add("ReData", "标记删除失败!");
CallBack();
}
}
else
{
ReceiveMessage.Add("StateCode", -2);
ReceiveMessage.Add("ReData", "移除邮件标记失败!");
CallBack();
}
}
示例8: AddBsonArray
public void AddBsonArray()
{
var person = new BsonDocument();
person.Add("Name", new BsonString("Nameirakpam"));
person.Add("address", new BsonArray(new[] {"Swapanalok","D-504","Pade Basti","Phursungi","Hadapsar"}));
Console.WriteLine(person.ToJson());
}
示例9: btnSearch_Click
/// <summary>
/// 全文检索功能
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnSearch_Click(object sender, EventArgs e)
{
//检索文法: http://docs.mongodb.org/manual/reference/command/text/#text-search-languages
//检索关键字
BsonDocument TextSearchOption = new BsonDocument().Add(new BsonElement("search", txtKey.Text));
//语言
if (cmbLanguage.SelectedIndex != 0)
{
TextSearchOption.Add(new BsonElement("language", cmbLanguage.Text));
}
//返回数限制
TextSearchOption.Add(new BsonElement("limit", (BsonValue) NUDLimit.Value));
try
{
CommandResult SearchResult = CommandHelper.ExecuteMongoColCommand("text",
SystemManager.GetCurrentCollection(), TextSearchOption);
Result = SearchResult.Response;
MongoDbHelper.FillDataToTreeView("Text Search Result", trvResult, Result);
cmdSave.Enabled = true;
}
catch (Exception ex)
{
SystemManager.ExceptionDeal(ex);
}
}
示例10: GetMarks
/// <summary>
/// 查询标记
/// </summary>
/// <param name="Data">查询条件</param>
/// <param name="ReceiveMessage">回调消息</param>
public void GetMarks(BsonDocument ReceiveMessage)
{
List<BsonDocument> MarkList = ms.FindMarks(new BsonDocument("ForCase", CaseInfo.CaseName));
ReceiveMessage.Add("StateCode", 0);
ReceiveMessage.Add("ReData", MarkList.ToJson(jsonSettings));
CallBack();
}
示例11: CreateEnglisthRecord
/* create english record */
static BsonDocument CreateEnglisthRecord()
{
BsonDocument obj = new BsonDocument();
try
{
obj.Add("name", "tom");
obj.Add("age", 60);
obj.Add("id", 2000);
// an embedded bson object
BsonDocument phone = new BsonDocument
{
{"0", "1808835242"},
{"1", "1835923246"}
};
obj.Add("phone", phone);
}
catch (Exception e)
{
Console.WriteLine("Failed to create record.");
Console.WriteLine(e.Message);
Environment.Exit(0);
}
return obj;
}
示例12: CreateChineseRecord
static BsonDocument CreateChineseRecord()
{
BsonDocument obj = new BsonDocument();
try
{
obj.Add("姓名", "杰克");
obj.Add("年龄", 70);
obj.Add("id", 2001);
// an embedded bson object
BsonDocument phone = new BsonDocument
{
{"0", "1808835242"},
{"1", "1835923246"}
};
obj.Add("电话", phone);
}
catch (Exception e)
{
Console.WriteLine("Failed to create record.");
Console.WriteLine(e.Message);
Environment.Exit(0);
}
return obj;
}
示例13: ConvertTreeNodeTozTreeBsonDoc
/// <summary>
///
/// </summary>
/// <param name="SubNode"></param>
/// <returns></returns>
private static BsonDocument ConvertTreeNodeTozTreeBsonDoc(TreeNode SubNode)
{
BsonDocument SingleNode = new BsonDocument();
SingleNode.Add("name", SubNode.Text + GetTagText(SubNode));
if (SubNode.Nodes.Count == 0)
{
SingleNode.Add("icon", "MainTreeImage" + String.Format("{0:00}", SubNode.ImageIndex) + ".png");
}
else
{
BsonArray ChildrenList = new BsonArray();
foreach (TreeNode item in SubNode.Nodes)
{
ChildrenList.Add(ConvertTreeNodeTozTreeBsonDoc(item));
}
SingleNode.Add("children", ChildrenList);
SingleNode.Add("icon", "MainTreeImage" + String.Format("{0:00}", SubNode.ImageIndex) + ".png");
}
if (SubNode.IsExpanded)
{
SingleNode.Add("open", "true");
}
if (SubNode.Tag != null)
{
SingleNode.Add("click", "ShowData('" + SystemManager.GetTagType(SubNode.Tag.ToString()) + "','" + SystemManager.GetTagData(SubNode.Tag.ToString()) + "')");
}
return SingleNode;
}
示例14: CreateUserAsync
public async Task<UserValidationResult> CreateUserAsync(User user)
{
var userDoc = new BsonDocument();
foreach (PropertyInfo prop in typeof(User).GetProperties())
{
if (prop.Name != "Id")
{
if (prop.GetValue(user) != null)
{
if (prop.Name == "Role")
{
userDoc.Add(prop.Name.ToLower(), new BsonDouble((int)(prop.GetValue(user) as Role?)));
}
else
{
userDoc.Add(prop.Name.ToLower(), new BsonString(prop.GetValue(user) as string));
}
}
else
{
userDoc.Add(prop.Name.ToLower(), new BsonString(string.Empty));
}
}
}
await _usersCollection.InsertOneAsync(userDoc).ConfigureAwait(false);
//check to see if user was actually inserted
var result = await GetUsersAsync(user);
return result;
}
示例15: AddCase
/// <summary>
/// 添加案件
/// </summary>
/// <param name="Options">添加信息</param>
/// <param name="ReceiveMessage">回掉消息</param>
public void AddCase(BsonDocument Options, BsonDocument ReceiveMessage)
{
String CaseName = Options.GetValue("CaseName").AsString;
String CaseDescription = Options.GetValue("CaseDescription").AsString;
ObjectId UserId = new ObjectId(Options.GetValue("AddUser").AsString);
int Type = Options.GetValue("Type").AsInt32;
if (cs.ExitCase(CaseName))
{
BsonDocument CaseDoc = new BsonDocument();
CaseDoc.Add("CaseName", CaseName);
CaseDoc.Add("CaseDescription", CaseDescription);
CaseDoc.Add("AddUser", UserId);
CaseDoc.Add("Type", Type);
CaseDoc.Add("AddTime", DateTime.Now);
if (cs.AddCase(CaseDoc))
{
ReceiveMessage.Add("StateCode", 0);
ReceiveMessage.Add("ReData", "案件添加成功!");
CallBack();
}
else
{
ReceiveMessage.Add("StateCode", -2);
ReceiveMessage.Add("ReData", "案件添加失败!");
CallBack();
}
}
else
{
ReceiveMessage.Add("StateCode", -1);
ReceiveMessage.Add("ReData", "案件已存在!");
CallBack();
}
}