本文整理汇总了C#中MongoCollection.FindOneAs方法的典型用法代码示例。如果您正苦于以下问题:C# MongoCollection.FindOneAs方法的具体用法?C# MongoCollection.FindOneAs怎么用?C# MongoCollection.FindOneAs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoCollection
的用法示例。
在下文中一共展示了MongoCollection.FindOneAs方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: GetByIdSession
private BsonDocument GetByIdSession(string IdSession, MongoCollection sessionCollection)
{
var query = Query.And(Query.EQ("_id", IdSession));
var result = sessionCollection.FindOneAs<BsonDocument>(query);
return result;
}
示例3: SetCurrentDocument
/// <summary>
/// Set Current Document
/// </summary>
/// <param name="currentNode"></param>
/// <param name="mongoCol"></param>
private static void SetCurrentDocument(TreeNode currentNode, MongoCollection mongoCol)
{
var rootNode = FindRootNode(currentNode);
//TODO:rootNode.Tag == null ???
if (rootNode.Tag == null) return;
var selectDocId = (BsonValue) rootNode.Tag;
var doc = mongoCol.FindOneAs<BsonDocument>(Query.EQ(ConstMgr.KeyId, selectDocId));
RuntimeMongoDbContext.CurrentDocument = doc;
}
示例4: Get
public GPSDataEntity Get(string gpsCode)
{
try
{
if (mongo.State == MongoServerState.Disconnected)
{
mongo.Connect();
}
MongoDB.Driver.MongoDatabase db = mongo.GetDatabase(dbName);
MongoCollection<GPSDataEntity> ps = new MongoCollection<GPSDataEntity>(db, tableName);
var query = new BsonDocument("GPSCode", gpsCode);
GPSDataEntity p = ps.FindOneAs<GPSDataEntity>(query);
return p;
}
catch (System.Exception ex)
{
Logger.Error(ex);
return null;
}
}
示例5: LoadJavascript
/// <summary>
/// 获得JS代码
/// </summary>
/// <param name="jsName"></param>
/// <param name="jsCol"></param>
/// <returns></returns>
public static string LoadJavascript(string jsName, MongoCollection jsCol)
{
if (QueryHelper.IsExistByKey(jsName))
{
var js = jsCol.FindOneAs<BsonDocument>(Query.EQ(ConstMgr.KeyId, jsName)).GetValue("value").ToString();
return js.IndexOf("new ", StringComparison.Ordinal) != -1 ? js.Substring(20, js.Length - 22) : js;
}
return string.Empty;
//var js = delegate(IMongoQuery query)
//{ return jsCol.FindOneAs<BsonDocument>(query).GetValue("value").ToString();
//};
}
示例6: LoadJavascript
/// <summary>
/// 获得JS代码
/// </summary>
/// <param name="jsName"></param>
/// <param name="jsCol"></param>
/// <returns></returns>
public static string LoadJavascript(string jsName, MongoCollection jsCol)
{
return QueryHelper.IsExistByKey(jsName)
? jsCol.FindOneAs<BsonDocument>(Query.EQ(ConstMgr.KeyId, jsName)).GetValue("value").ToString()
: string.Empty;
}
示例7: findOne
public dynamic findOne(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.FindOneAs<BsonDocument>(query);
if(null!=result)
return new Entity(result);
return null;
}
throw new NotImplementedException("Only annonymous types are accepted for Queries.");
}