本文整理汇总了C#中MongoCollection类的典型用法代码示例。如果您正苦于以下问题:C# MongoCollection类的具体用法?C# MongoCollection怎么用?C# MongoCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MongoCollection类属于命名空间,在下文中一共展示了MongoCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddUserEx
/// <summary>
/// Adds a user to this database.
/// </summary>
/// <param name="user">The user.</param>
public static void AddUserEx(MongoCollection Col, User user)
{
var document = Col.FindOneAs<BsonDocument>(Query.EQ("user", user.Username));
if (document == null)
{
document = new BsonDocument("user", user.Username);
}
document["roles"] = user.roles;
if (document.Contains("readOnly"))
{
document.Remove("readOnly");
}
//必须要Hash一下Password
document["pwd"] = MongoUser.HashPassword(user.Username, user.Password);
//OtherRole 必须放在Admin.system.users里面
if (Col.Database.Name == MongoDbHelper.DATABASE_NAME_ADMIN)
{
document["otherDBRoles"] = user.otherDBRoles;
}
if (string.IsNullOrEmpty(user.Password))
{
document["userSource"] = user.userSource;
}
Col.Save(document);
}
示例2: ChooseAction
private static void ChooseAction(MongoCollection<Word> words)
{
string action = Console.ReadLine();
switch (action)
{
case "1":
ReadWord(words);
break;
case "2":
ListWords(words);
break;
case "3":
FindWords(words);
break;
case "4":
DisplayStartupMenu();
break;
case "exit":
Console.WriteLine("Goodbuy!");
return;
default:
Console.WriteLine("Invalid action, please choose again.");
break;
}
ChooseAction(words);
}
示例3: FromLevel1RecordCollectionToLevelTopRecords
/// <summary>
/// LevelTop只能有一个
/// </summary>
/// <param name="flight"></param>
/// <param name="collection"></param>
/// <returns></returns>
public LevelTopFlightRecord FromLevel1RecordCollectionToLevelTopRecords(
Flight flight, MongoCollection<Level1FlightRecord> collection)
{
FlightParameter[] parameters = this.GetParameters();
Dictionary<string, LevelTopFlightRecord> topRecordMaps = new Dictionary<string, LevelTopFlightRecord>();
Dictionary<LevelTopFlightRecord, List<Level2FlightRecord>> level2RecordMap
= new Dictionary<LevelTopFlightRecord, List<Level2FlightRecord>>();
List<LevelTopFlightRecord> topRecords = new List<LevelTopFlightRecord>();
foreach (FlightParameter para in parameters)
{
LevelTopFlightRecord topRecord = new LevelTopFlightRecord()
{
StartSecond = flight.StartSecond,
EndSecond = flight.EndSecond,
ParameterID = para.ParameterID,
};
topRecordMaps.Add(para.ParameterID, topRecord);
level2RecordMap.Add(topRecord, new List<Level2FlightRecord>());
for (int currentSecond = flight.StartSecond; currentSecond > flight.EndSecond; currentSecond += SecondGap)
{
int step = SecondGap;
Level2FlightRecord level2 = this.HandleOneStep(currentSecond, step, para,
topRecord, flight, collection);
level2RecordMap[topRecord].Add(level2);
}
}
return null;//DEBUG
//return topRecords.ToArray();
}
示例4: ChangeTranslation
private static void ChangeTranslation(MongoCollection english)
{
Console.WriteLine("Enter word.");
string word = Console.ReadLine();
Console.WriteLine("Enter translation.");
string translation = Console.ReadLine();
if (!string.IsNullOrWhiteSpace(word) && !string.IsNullOrWhiteSpace(translation))
{
var query = Query.And(Query.EQ("Name", word));
var filtered = english.FindAs<Word>(query);
var count = filtered.Count();
if (count > 0)
{
foreach (var item in filtered)
{
var update = Update.Set("Translation", translation);
var queryId = Query.EQ("_id", item.Id);
english.Update(queryId, update);
Console.WriteLine("Translation of the word {0} is changed.", word);
}
}
else
{
Console.WriteLine("There is no word {0}.", word);
}
}
else
{
Console.WriteLine("You enter null or empty string for word or translation. Please try again.");
}
}
示例5: MongoInsertOptions
/// <summary>
/// Initializes a new instance of the MongoInsertOptions class.
/// </summary>
/// <param name="collection">The collection from which to get default settings for the options.</param>
public MongoInsertOptions(
MongoCollection collection
) {
this.checkElementNames = true;
this.flags = InsertFlags.None;
this.safeMode = collection.Settings.SafeMode;
}
示例6: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document)
{
var projectIds = document.GetValue("ProjectIds").AsBsonArray.Select(p => p.AsInt32).ToList();
document.Remove("ProjectIds");
document.Add("ProjectIds", new BsonArray(projectIds.Select(x => x.ToString())));
collection.Save(document);
}
示例7: Run
public IEnumerable<BsonDocument> Run(MongoCollection<Rental> rentals)
{
var priceRange = new BsonDocument(
"$subtract",
new BsonArray
{
"$Price",
new BsonDocument(
"$mod",
new BsonArray{"$Price",500}
)
});
var grouping =new BsonDocument(
"$group",
new BsonDocument
{
{"_id",priceRange},
{"count",new BsonDocument("$sum",1)}
});
var sort=new BsonDocument(
"$sort",
new BsonDocument("_id",1)
);
var args=new AggregateArgs
{
Pipeline=new []{grouping,sort}
};
return rentals.Aggregate(args);
}
示例8: TestFixtureSetup
public void TestFixtureSetup()
{
_database = Configuration.TestDatabase;
var collectionSettings = new MongoCollectionSettings() { GuidRepresentation = GuidRepresentation.Standard };
_collection = _database.GetCollection<C>("csharp714", collectionSettings);
_collection.Drop();
}
示例9: Find
public IEnumerable<IDictionary<string, object>> Find(MongoCollection<BsonDocument> collection, SimpleQuery query, out IEnumerable<SimpleQueryClauseBase> unhandledClauses)
{
var builder = MongoQueryBuilder.BuildFrom(query);
unhandledClauses = builder.UnprocessedClauses;
if (builder.IsTotalCountQuery)
{
long count;
if (builder.Criteria == null)
count = collection.Count();
else
count = collection.Count(_expressionFormatter.Format(builder.Criteria));
//TODO: figure out how to make count a long
builder.SetTotalCount((int)count);
}
if (!builder.SkipCount.HasValue && builder.TakeCount.HasValue && builder.TakeCount.Value == 1)
return new[] { FindOne(collection, builder.Criteria) };
var cursor = CreateCursor(collection, builder.Criteria);
ApplyFields(cursor, builder.Columns);
ApplySorting(cursor, builder.Order);
ApplySkip(cursor, builder.SkipCount);
ApplyTake(cursor, builder.TakeCount);
var aliases = builder.Columns.OfType<ObjectReference>().ToDictionary(x => ExpressionFormatter.GetFullName(x), x => x.GetAlias());
return cursor.Select(x => x.ToSimpleDictionary(aliases));
}
示例10: AddToDictionary
private static void AddToDictionary(MongoCollection english)
{
Console.WriteLine("Enter word.");
string word = Console.ReadLine();
Console.WriteLine("Enter translation.");
string translation = Console.ReadLine();
if (!string.IsNullOrWhiteSpace(word) && !string.IsNullOrWhiteSpace(translation))
{
var query = Query.And(Query.EQ("Name", word));
var filtered = english.FindAs<Word>(query);
var count = filtered.Count();
if (count == 0)
{
english.Insert(new Word(word, translation));
Console.WriteLine("The word {0} is added.", word);
}
else
{
Console.WriteLine("The word {0} is already added.", word);
}
}
else
{
Console.WriteLine("You enter null or empty string for word or translation. Please try again.");
}
}
示例11: GetAroundYouArticles
private IEnumerable<ArticleWebDto> GetAroundYouArticles(
MongoCollection<ArticleDto> articles,
string lngString,
string latString,
CultureInfo culture)
{
var innerMaxDistance = 3.0d;
var outerMaxDistance = 5.0d;
var innerMaxDistanceString = (innerMaxDistance / EarthRadius).ToString(culture.NumberFormat);
var outerMaxDistanceString = (outerMaxDistance / EarthRadius).ToString(culture.NumberFormat);
var jsonQuery = "{$and:[ " +
"{'location':{$geoWithin:{$centerSphere:[[" + lngString + "," + latString + "]," + outerMaxDistanceString + "]}}}," +
"{'location':{$not:{$geoWithin:{$centerSphere:[[" + lngString + "," + latString + "]," + innerMaxDistanceString + "]}}} }," +
"]}";
var doc = BsonSerializer.Deserialize<BsonDocument>(jsonQuery);
var query = new QueryDocument(doc);
var results = articles.Find(query).SetSortOrder(new SortByBuilder().Descending("publishedAt")).SetLimit(50);
var dtos = results.ToList().Select(ConvertArticleDtoToArticleWebDto());
return dtos;
}
示例12: frmQuery
/// <summary>
/// 初始化
/// </summary>
/// <param name="mDataViewInfo">Filter也是DataViewInfo的一个属性,所以这里加上参数</param>
public frmQuery(MongoDBHelper.DataViewInfo mDataViewInfo)
{
InitializeComponent();
CurrentDataViewInfo = mDataViewInfo;
SystemManager.SelectObjectTag = mDataViewInfo.strDBTag;
_mongoCol = SystemManager.GetCurrentCollection();
}
示例13: TestFixtureSetup
public void TestFixtureSetup()
{
_server = Configuration.TestServer;
_database = Configuration.TestDatabase;
_collection = Configuration.TestCollection;
_collection.Drop();
}
示例14: Setup
public void Setup()
{
server = MongoServer.Create("mongodb://localhost/?safe=true");
server.Connect();
database = server["onlinetests"];
collection = database["testcollection"];
}
示例15: EstablishConnection
public static void EstablishConnection()
{
client = new MongoClient(connectionString);
server = client.GetServer();
database = server.GetDatabase(DbName);
entries = database.GetCollection<JSonReport>(collectionName);
}