本文整理汇总了C#中BsonDocument.AddRange方法的典型用法代码示例。如果您正苦于以下问题:C# BsonDocument.AddRange方法的具体用法?C# BsonDocument.AddRange怎么用?C# BsonDocument.AddRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BsonDocument
的用法示例。
在下文中一共展示了BsonDocument.AddRange方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMatchDocument
/// <summary>
/// 获取Match
/// </summary>
/// <returns></returns>
public BsonDocument GetMatchDocument()
{
var matchlist = new BsonDocument();
foreach (Control item in Controls)
{
if (item.GetType().FullName == typeof(Button).FullName) continue;
var match = ((CtlMatchItem)item).GetMatchItem();
if (match != null)
{
var matchName = match.GetElement(0).Name;
if (matchlist.Contains(matchName))
{
var addMatch = match.GetElement(0).Value.AsBsonDocument;
matchlist.GetElement(matchName).Value.AsBsonDocument.AddRange(addMatch);
}
else
{
matchlist.AddRange(match);
}
}
}
if (matchlist.ElementCount > 0)
{
return new BsonDocument("$match", matchlist);
}
return null;
}
示例2: GetMatchDocument
/// <summary>
/// 获取Match
/// </summary>
/// <returns></returns>
public BsonDocument GetMatchDocument()
{
var matchlist = new BsonDocument();
foreach (CtlMatchItem item in Controls)
{
var match = item.GetMatchItem();
if (match != null)
{
var matchName = match.GetElement(0).Name;
if (matchlist.Contains(matchName))
{
var addMatch = match.GetElement(0).Value.AsBsonDocument;
matchlist.GetElement(matchName).Value.AsBsonDocument.AddRange(addMatch);
}
else
{
matchlist.AddRange(match);
}
}
}
if (matchlist.ElementCount > 0)
{
return new BsonDocument("$match", matchlist);
}
return null;
}
示例3: GetMatchDocument
/// <summary>
/// 获取Match
/// </summary>
/// <returns></returns>
public BsonDocument GetMatchDocument()
{
var Matchlist = new BsonDocument();
foreach (ctlMatchItem item in Controls)
{
BsonDocument match = item.getMatchItem();
if (match != null)
{
string MatchName = match.GetElement(0).Name;
if (Matchlist.Contains(MatchName))
{
BsonDocument AddMatch = match.GetElement(0).Value.AsBsonDocument;
Matchlist.GetElement(MatchName).Value.AsBsonDocument.AddRange(AddMatch);
}
else
{
Matchlist.AddRange(match);
}
}
}
if (Matchlist.ElementCount > 0)
{
return new BsonDocument("$match", Matchlist);
}
return null;
}
示例4: Group
/// <summary>
/// Generates a $group pipeline command based upon the specified group-by and grouping-aggregation specifications
/// </summary>
/// <param name="GroupBy">The group-by specification for grouping distinction</param>
/// <param name="Aggregations">An enumerable of grouping-aggregation expressions</param>
public static BsonDocument Group(BsonElement GroupBy, IEnumerable<BsonElement> Aggregations)
{
var value = new BsonDocument(GroupBy);
if (Aggregations != null && Aggregations.Any()) {
value.AddRange(Aggregations);
}
return new BsonDocument() { { "$group", value } };
}
示例5: CreateFilterQuery
public BsonDocument CreateFilterQuery(IList<QueryInfo> filterParams)
{
BsonDocument filterQuery = new BsonDocument();
foreach (var item in filterParams)
{
BsonDocument newFilter = new BsonDocument(item.Key, new BsonDocument(item.QueryOperator, item.Value));
filterQuery.AddRange(newFilter);
}
return filterQuery;
}
示例6: GetFlatDocument
public BsonDocument GetFlatDocument(BsonDocument document)
{
BsonDocument flatDocument = new BsonDocument();
flatDocument.AllowDuplicateNames = true;
flatDocument.AddRange(GetElements(document));
//foreach (BsonElement element in new EnumerateElements { Options = options }.GetElements(document))
//{
// if (!flatDocument.Contains(element.Name))
// flatDocument.Add(element);
// else
// Trace.WriteLine("warning duplicate \"{0}\" : value1 {1} value2 {2}", element.Name, flatDocument[element.Name], element.Value);
//}
return flatDocument;
}
示例7: UpdateDocument
protected override void UpdateDocument(BsonDocument document, Func<BsonDocument, UpdateCompiler> update)
{
var copy = document.DeepClone();
try
{
update(document);
}
catch
{
document.Clear();
document.AddRange(copy.AsBsonDocument);
throw;
}
}
示例8: EntryToDocument
private void EntryToDocument(IndexValue indexValue, int level, List<BsonDocument> result)
{
//Add the real values (not contained) to a document and add that to the result.
List<IndexValue> notNestedValues = indexValue.Values.Where(exp => (exp is IndexValue) && ((IndexValue)exp).Name != "contained").Select(exp => (IndexValue)exp).ToList();
var doc = new BsonDocument(new BsonElement(InternalField.LEVEL, level));
doc.AddRange(notNestedValues.Select(iv => IndexValueToElement(iv)));
result.Add(doc);
//Then do that recursively for all contained indexed resources.
List<IndexValue> containedValues = indexValue.Values.Where(exp => (exp is IndexValue) && ((IndexValue)exp).Name == "contained").Select(exp => (IndexValue)exp).ToList();
foreach (var contained in containedValues)
{
EntryToDocument(contained, level + 1, result);
}
}
示例9: ToMatchDocument
public static BsonDocument ToMatchDocument(this MatchDefinition source)
{
var result = new BsonDocument();
var matchFilterElements = new List<BsonElement>();
source.Filters.Where(x=>x.AvailableFilterValues.Any(y=>y.Active)).ToList().ForEach(f =>
{
var colDoc = new BsonDocument();
var selectedValues = new BsonArray();
var selectedFilterValues = f.AvailableFilterValues.Where(x=>x.Active).Select(x => x.Value).Select(x => new BsonString(x)).ToList();
selectedValues.AddRange(selectedFilterValues);
//var itemE
var itemElm = new BsonElement("$in", selectedValues);
colDoc.Add(itemElm);
var colElm = new BsonElement(f.Column.ColumnName, colDoc);
matchFilterElements.Add(colElm);
});
var elementsDoc = new BsonDocument();
elementsDoc.AddRange(matchFilterElements);
var matchElement = new BsonElement("$match", elementsDoc);
result.Add(matchElement);
return result;
}
示例10: GeoNear
public NoSqlPipeline GeoNear(double[] location, string distanceField, params BsonElement[] opts)
{
if (Pipeline.Count > 0)
{
throw new InvalidOperationException("You can only use $geoNear as the first stage of a pipeline.");
}
if (location.Length != 2)
{
throw new InvalidOperationException("location[] must contain two double values.");
}
var doc = new BsonDocument
{
{ "near", new BsonArray(location) },
{ "distanceField", distanceField }
};
doc.AddRange(opts);
Pipeline.Add(new BsonDocument { { "$geoNear", doc } });
Fields.Add("dist");
return this;
}
示例11: CreateBsonDocument
public BsonDocument CreateBsonDocument()
{
BsonDocument bsonDocument = new BsonDocument();
bsonDocument.AddRange(GetDBKeyVal());
return bsonDocument;
}
示例12: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
try
{
var obj = Request["reqdata"];
BsonDocument t = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonDocument>(obj);
BsonValue objOrg = t.GetElement("originalGridData").Value;
BsonValue objDummy = t.GetElement("dummyGridData").Value;
MyDB db = new MyDB();
string merchatsess = Session["dedcolname"].ToString();
string merchdummycoll = Session["dummycol"].ToString();
var coll = db.GetBColl(merchatsess);
var dummycoll = db.GetBColl(merchdummycoll);
if (coll.Count() > 0)
{
coll.Drop();
}
List<object> orgList = new List<object>();
BsonDocument bexp = new BsonDocument();
var coll77 = db.GetBColl(merchatsess);
for (int i = 0; i <= objOrg.AsBsonArray.Count - 1; i++)
{
bexp = new BsonDocument();
var bids = objOrg[i].AsBsonDocument;
bexp.AddRange(bids);
orgList.Add(bexp);
bexp = null;
}
coll77.InsertBatch(orgList);
BsonDocument bdums = new BsonDocument();
BsonDocument bdums1 = new BsonDocument();
var dummycount = dummycoll.Count();
if (dummycoll.Exists() && dummycount > 0)
{
var maxsnosno = dummycoll.FindAll().SetSortOrder(SortBy.Descending("sno")).SetLimit(1).FirstOrDefault();
var bsonsno = maxsnosno.GetElement("sno").Value;
var longsno = Convert.ToInt64(bsonsno);
for (int i = 0; i <= objDummy.AsBsonArray.Count - 1; i++)
{
longsno++;
bdums = new BsonDocument();
Dictionary<string, long> dict = new Dictionary<string, long>();
dict.Add("sno", longsno);
var biddums = objDummy[i].AsBsonDocument;
bdums.AddRange(biddums);
bdums.AddRange(dict);
dummycoll.Insert(bdums);
bdums = null;
}
}
else
{
var longsno1 = 0;
for (int i = 0; i <= objDummy.AsBsonArray.Count - 1; i++)
{
longsno1++;
bdums1 = new BsonDocument();
Dictionary<string, long> mydict = new Dictionary<string, long>();
mydict.Add("sno", longsno1);
var biddums1 = objDummy[i].AsBsonDocument;
bdums1.AddRange(biddums1);
bdums1.AddRange(mydict);
dummycoll.Insert(bdums1);
bdums1 = null;
}
}
string f_dedcoll = Session["dedcolname"].ToString();
var f_coll = db.GetBColl(f_dedcoll);
IEnumerable<BsonValue> typesregex = f_coll.Distinct("type");
var outjson = "";
var outjsonconcat = "";
var varjson = "";
BsonElement btype = null;
BsonValue btypevalue = null;
BsonElement bmeasures = null;
string dums = null;
var jsonoffer = "";
foreach (string str in typesregex)
{
dums = null;
var query = new QueryDocument("type", str);
foreach (BsonDocument docs in f_coll.Find(query))
{
btype = docs.GetElement("type");
btypevalue = btype.Value;
bmeasures = docs.GetElement("measures");
string bmes = bmeasures.ToString();
var s = bmes.Replace(";", "\",\"");
var squareconcat = "[" + "\"" + s.Substring(9) + "\"" + "]";
var addtobson = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonValue>(squareconcat);
docs.Remove("_id");
//.........这里部分代码省略.........
示例13: btnOK_Click
/// <summary>
/// OK
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnOK_Click(object sender, EventArgs e)
{
//Project
var project = QueryFieldPicker.GetAggregation();
var supressAggr = project[0];
var projectAggr = project[1];
if (supressAggr[0].AsBsonDocument.ElementCount > 0)
{
Aggregation.Add(supressAggr);
}
//TODO:需要优化,全项目的时候,不用输出
if (projectAggr[0].AsBsonDocument.ElementCount > 0)
{
Aggregation.Add(projectAggr);
}
//match
var match = ConditionPan.GetMatchDocument();
if (match != null)
{
Aggregation.Add(match);
}
//Sort
var sort = SortPanel.GetSortDocument();
if (sort != null)
{
Aggregation.Add(sort);
}
//Group
if (chkIdNull.Checked)
{
var id = new BsonDocument();
id.Add(new BsonElement("_id", BsonNull.Value));
id.AddRange(FieldsElement.Value.AsBsonDocument.Elements);
var group = new BsonDocument("$group", id);
Aggregation.Add(group);
}
else
{
if (!string.IsNullOrEmpty(GroupIdElement.Name))
{
var id = new BsonDocument();
id.Add(new BsonElement("_id", GroupIdElement.Value));
id.AddRange(FieldsElement.Value.AsBsonDocument.Elements);
var group = new BsonDocument("$group", id);
Aggregation.Add(group);
}
}
//Skip
if (chkSkip.Checked && int.Parse(txtSkip.Text) > 0)
{
Aggregation.Add(new BsonDocument("$skip", int.Parse(txtSkip.Text)));
}
//Limit
if (chkLimit.Checked && int.Parse(txtLimit.Text) > 0)
{
Aggregation.Add(new BsonDocument("$limit", int.Parse(txtLimit.Text)));
}
//IndexStats
if (chkIndexStats.Checked)
{
Aggregation.Add(new BsonDocument("$indexStats", new BsonDocument()));
}
//sortByCount
if (chkSortByCount.Checked)
{
Aggregation.Add(new BsonDocument("$sortByCount", cmbSortByCount.Text));
}
//Sample
if (chkSample.Checked)
{
var size = new BsonDocument("size", (int.Parse(txtSample.Text)));
Aggregation.Add(new BsonDocument("$sample", size));
}
//unwind
if (chkUnwind.Checked)
{
if (!chkPreserveNullAndEmptyArrays.Checked && string.IsNullOrEmpty(txtincludeArrayIndex.Text))
{
Aggregation.Add(new BsonDocument("$unwind", cmbUnwind.Text));
}
else
{
var UnwindDoc = new BsonDocument();
var field = new BsonElement("path", cmbUnwind.Text);
UnwindDoc.Add(field);
if (chkPreserveNullAndEmptyArrays.Checked)
{
var preserveNullAndEmptyArrays = new BsonElement("preserveNullAndEmptyArrays", BsonBoolean.True);
UnwindDoc.Add(preserveNullAndEmptyArrays);
}
if (!string.IsNullOrEmpty(txtincludeArrayIndex.Text))
//.........这里部分代码省略.........
示例14: ToGroup
static IEnumerable<BsonElement> ToGroup(this GroupDefinition source)
{
var result = new BsonDocument();
var groupDoc = new BsonDocument();
//
groupDoc.AddRange(source.ToId());
groupDoc.AddRange(source.ToFact());
var groupElement = new BsonElement("$group", groupDoc);
result.Add(groupElement);
return result;
}
示例15: UpdateDocument
protected override void UpdateDocument(BsonDocument document, Func<BsonDocument, UpdateCompiler> update)
{
var oldId = document[MyValue.Id];
var copy = document.DeepClone();
try
{
update(document);
BsonValue newId;
if (!document.TryGetValue(MyValue.Id, out newId) || !oldId.Equals(newId))
throw new InvalidOperationException("Modification of _id is not allowed.");
}
catch
{
document.Clear();
document.AddRange(copy.AsBsonDocument);
throw;
}
}