本文整理汇总了C#中MongoCollection类的典型用法代码示例。如果您正苦于以下问题:C# MongoCollection类的具体用法?C# MongoCollection怎么用?C# MongoCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MongoCollection类属于命名空间,在下文中一共展示了MongoCollection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:EricBlack,项目名称:MagicMongoDBTool,代码行数:29,代码来源:User.cs
示例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);
}
开发者ID:hristo-iliev,项目名称:TelerikHW,代码行数:28,代码来源:MongoDictionary.cs
示例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();
}
开发者ID:K-Library-NET,项目名称:PopcornStudios,代码行数:40,代码来源:DefaultLevel1ToLevelTopRecordStrategy.cs
示例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.");
}
}
开发者ID:vasilkrvasilev,项目名称:Databases,代码行数:31,代码来源:MongoDbDictionary.cs
示例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;
}
开发者ID:snedzad,项目名称:mongo-csharp-driver,代码行数:11,代码来源:MongoInsertOptions.cs
示例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);
}
开发者ID:apxnowhere,项目名称:Encore,代码行数:7,代码来源:ChangeFieldProjectIdToString.cs
示例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);
}
开发者ID:nywebman,项目名称:MongoDBdotNet,代码行数:31,代码来源:QueryPriceDistribution.cs
示例8: TestFixtureSetup
public void TestFixtureSetup()
{
_database = Configuration.TestDatabase;
var collectionSettings = new MongoCollectionSettings() { GuidRepresentation = GuidRepresentation.Standard };
_collection = _database.GetCollection<C>("csharp714", collectionSettings);
_collection.Drop();
}
开发者ID:GGsus,项目名称:mongo-csharp-driver,代码行数:7,代码来源:CSharp714Tests.cs
示例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));
}
开发者ID:kppullin,项目名称:Simple.Data.MongoDB,代码行数:32,代码来源:MongoAdapterFinder.cs
示例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.");
}
}
开发者ID:vasilkrvasilev,项目名称:Databases,代码行数:26,代码来源:MongoDbDictionary.cs
示例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;
}
开发者ID:Cosmo,项目名称:News-Sightseeing,代码行数:25,代码来源:DiscoverController.cs
示例12: Upsert
protected bool Upsert(MongoCollection<object> collection, object obj, Guid id)
{
if (collection.FindOneById(id) != null)
return collection.Update(Query.EQ("_id", id), Update.Replace(obj), WriteConcern.Acknowledged).Ok;
else
return Add(collection, obj);
}
开发者ID:pitlabcloud,项目名称:activity-cloud,代码行数:7,代码来源:BaseRegistry.cs
示例13: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
ObjectId organizationId = document.GetValue(ProjectRepository.FieldNames.OrganizationId).AsObjectId;
var users = Database.GetCollection(UserRepository.CollectionName)
.Find(Query.In(UserRepository.FieldNames.OrganizationIds, new List<BsonValue> {
organizationId
}))
.SetFields(ProjectRepository.FieldNames.Id).ToList();
if (!document.Contains(ProjectRepository.FieldNames.NotificationSettings))
document.Add(ProjectRepository.FieldNames.NotificationSettings, new BsonDocument());
BsonDocument settings = document.GetValue(ProjectRepository.FieldNames.NotificationSettings).AsBsonDocument;
foreach (var user in users) {
var userId = user.GetValue(ProjectRepository.FieldNames.Id).AsObjectId.ToString();
if (!settings.Contains(userId))
settings.Add(userId, new BsonDocument());
var userSettings = settings.GetValue(userId).AsBsonDocument;
if (!userSettings.Contains("SendDailySummary"))
userSettings.Add("SendDailySummary", new BsonBoolean(true));
else
userSettings.Set("SendDailySummary", new BsonBoolean(true));
}
collection.Save(document);
}
开发者ID:khoussem,项目名称:Exceptionless,代码行数:26,代码来源:v1.0.22.cs
示例14: HandleOneStep
private Level2FlightRecord HandleOneStep(int currentSecond, int step, FlightParameter para,
LevelTopFlightRecord topRecord, Flight flight, MongoCollection<Level1FlightRecord> collection)
{
IMongoQuery query = Query.And(Query.EQ("ParameterID", new BsonString(para.ParameterID)),
Query.GTE("FlightSecond", new BsonInt32(currentSecond)),
Query.LT("FlightSecond", new BsonInt32(currentSecond + step)));
MongoCursor<Level1FlightRecord> flightRecord = collection.Find(query);
Level2FlightRecord level2 = new Level2FlightRecord()
{
StartSecond = currentSecond,
EndSecond = Math.Min(flight.EndSecond, currentSecond + step),
// Level1FlightRecords = flightRecord.ToArray(),
ParameterID = para.ParameterID,
};
//var sum = from one in level2.Level1FlightRecords
// select one.ValueCount;
//level2.Count = sum.Sum();
//var avg = from one in level2.Level1FlightRecords
// select one.AvgValue;
//level2.AvgValue = avg.Sum() * level2.Count;
//var min = from one in level2.Level1FlightRecords
// select one.MinValue;
//level2.MinValue = min.Min();
//var max = from one in level2.Level1FlightRecords
// select one.MaxValue;
//level2.MaxValue = max.Max();
return level2;
}
开发者ID:K-Library-NET,项目名称:PopcornStudios,代码行数:35,代码来源:DefaultLevel1ToLevelTopRecordStrategy.cs
示例15: find
public dynamic find(MongoCollection collection,object[] args)
{
Type type = args[0].GetType();
if(type.Name.Contains("<>__AnonType")){
PropertyInfo[] properties = type.GetProperties();
Dictionary<string,object> dictionary = new Dictionary<string, object>();
foreach(var property in properties)
dictionary[property.Name] = property.GetValue(args[0],null);
var query = new QueryDocument(dictionary);
var result = collection.FindAs<BsonDocument>(query);
List<Entity> documents = new List<Entity>();
if(result.Size() > 0)
{
foreach(var entity in result)
documents.Add(new Entity(entity));
}
return documents;
}
throw new NotImplementedException("Only annonymous types are accepted for Queries.");
}
开发者ID:blackorzar,项目名称:DMongo,代码行数:25,代码来源:DBExpando.cs
示例16: frmQuery
/// <summary>
/// 初始化
/// </summary>
/// <param name="mDataViewInfo">Filter也是DataViewInfo的一个属性,所以这里加上参数</param>
public frmQuery(MongoDBHelper.DataViewInfo mDataViewInfo)
{
InitializeComponent();
CurrentDataViewInfo = mDataViewInfo;
SystemManager.SelectObjectTag = mDataViewInfo.strDBTag;
_mongoCol = SystemManager.GetCurrentCollection();
}
开发者ID:china0zzl,项目名称:MagicMongoDBTool,代码行数:11,代码来源:frmQuery.cs
示例17: TestFixtureSetup
public void TestFixtureSetup()
{
_server = Configuration.TestServer;
_database = Configuration.TestDatabase;
_collection = Configuration.TestCollection;
_collection.Drop();
}
开发者ID:annikulin,项目名称:code-classifier,代码行数:7,代码来源:CSharp282Tests.cs
示例18: Setup
public void Setup()
{
server = MongoServer.Create("mongodb://localhost/?safe=true");
server.Connect();
database = server["onlinetests"];
collection = database["testcollection"];
}
开发者ID:modesto,项目名称:mongo-csharp-driver,代码行数:7,代码来源:MongoCollectionTests.cs
示例19: EstablishConnection
public static void EstablishConnection()
{
client = new MongoClient(connectionString);
server = client.GetServer();
database = server.GetDatabase(DbName);
entries = database.GetCollection<JSonReport>(collectionName);
}
开发者ID:VyaraGGeorgieva,项目名称:TelerikAcademy,代码行数:7,代码来源:MongoDbReportReader.cs
示例20: CommandEnvelopeRouteOnRequestCostcentreRepository
public CommandEnvelopeRouteOnRequestCostcentreRepository(string connectionString)
: base(connectionString)
{
_commandEnvelopeRouteOnRequestCostcentreCollection = CurrentMongoDB.GetCollection<CommandEnvelopeRouteOnRequestCostcentre>(_commandEnvelopeRouteOnRequestCostcentreCollectionName);
_commandEnvelopeRouteOnRequestCostcentreCollection.EnsureIndex(IndexKeys<CommandEnvelopeRouteOnRequestCostcentre>.Ascending(n => n.Id), IndexOptions.SetUnique(true));
_commandEnvelopeRouteOnRequestCostcentreCollection.EnsureIndex(IndexKeys<CommandEnvelopeRouteOnRequestCostcentre>.Ascending(n => n.EnvelopeId));
_commandEnvelopeRouteOnRequestCostcentreCollection.EnsureIndex(IndexKeys<CommandEnvelopeRouteOnRequestCostcentre>.Ascending(n => n.CostCentreId));
_commandEnvelopeRouteOnRequestCostcentreCollection.EnsureIndex(IndexKeys<CommandEnvelopeRouteOnRequestCostcentre>.Ascending(n => n.EnvelopeRoutePriority));
_commandEnvelopeRouteOnRequestCostcentreCollection.EnsureIndex(IndexKeys<CommandEnvelopeRouteOnRequestCostcentre>.Ascending(n => n.EnvelopeArrivalAtServerTick));
_commandEnvelopeRouteOnRequestCostcentreCollection.EnsureIndex(IndexKeys<CommandEnvelopeRouteOnRequestCostcentre>.Ascending(n => n.DocumentType));
_commandEnvelopeRoutingStatusCollection = CurrentMongoDB.GetCollection<CommandEnvelopeRoutingStatus>(_commandEnvelopeRoutingStatusCollectionName);
_commandEnvelopeRoutingStatusCollection.EnsureIndex(IndexKeys<CommandEnvelopeRoutingStatus>.Ascending(n => n.Id), IndexOptions.SetUnique(true));
_commandEnvelopeRoutingStatusCollection.EnsureIndex(IndexKeys<CommandEnvelopeRoutingStatus>.Ascending(n => n.DestinationCostCentreApplicationId));
_commandEnvelopeRoutingStatusCollection.EnsureIndex(IndexKeys<CommandEnvelopeRoutingStatus>.Ascending(n => n.EnvelopeDeliveredAtServerTick));
_commandEnvelopeProcessingAuditCollection = CurrentMongoDB.GetCollection<CommandEnvelopeProcessingAudit>(_commandEnvelopeProcessingAuditCollectionName);
_commandEnvelopeProcessingAuditCollection.EnsureIndex(IndexKeys<CommandEnvelopeProcessingAudit>.Ascending(n => n.Id), IndexOptions.SetUnique(true));
_commandEnvelopeProcessingAuditCollection.EnsureIndex(IndexKeys<CommandEnvelopeProcessingAudit>.Ascending(n => n.GeneratedByCostCentreApplicationId));
_commandEnvelopeProcessingAuditCollection.EnsureIndex(IndexKeys<CommandEnvelopeProcessingAudit>.Ascending(n => n.RecipientCostCentreId));
_commandEnvelopeProcessingAuditCollection.EnsureIndex(IndexKeys<CommandEnvelopeProcessingAudit>.Ascending(n => n.DocumentId));
_commandEnvelopeProcessingAuditCollection.EnsureIndex(IndexKeys<CommandEnvelopeProcessingAudit>.Ascending(n => n.Status));
_commandEnvelopeProcessingAuditCollection.EnsureIndex(IndexKeys<CommandProcessingAudit>.Ascending(n => n.ParentDocumentId));
_commandEnvelopeProcessingAuditCollection.EnsureIndex(IndexKeys<CommandProcessingAudit>.Ascending(n => n.DateInserted));
_CommandEnvelopeRoutingTrackerCollection = CurrentMongoDB.GetCollection<CommandEnvelopeRoutingTracker>(_commandEnvelopeRoutingTrackerCollectionName);
_CommandEnvelopeRoutingTrackerCollection.CreateIndex(IndexKeys<CommandEnvelopeRoutingTracker>.Ascending(n => n.Id), IndexOptions.SetUnique(true));
_CommandEnvelopeRoutingTrackerCollection.CreateIndex(IndexKeys<CommandEnvelopeRoutingTracker>.Ascending(n => n.EnvelopeArrivalAtServerTick));
_CommandEnvelopeRoutingTrackerCollection.CreateIndex(IndexKeys<CommandEnvelopeRoutingTracker>.Ascending(n => n.EnvelopeId));
}
开发者ID:asanyaga,项目名称:BuildTest,代码行数:31,代码来源:CommandEnvelopeRouteOnRequestCostcentreRepository.cs
注:本文中的MongoCollection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论