本文整理汇总了C#中MongoDB.Driver.Document.Append方法的典型用法代码示例。如果您正苦于以下问题:C# Document.Append方法的具体用法?C# Document.Append怎么用?C# Document.Append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Driver.Document
的用法示例。
在下文中一共展示了Document.Append方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCalculateSizeOfComplexDoc
public void TestCalculateSizeOfComplexDoc()
{
Document doc = new Document();
doc.Append("a","a");
doc.Append("b",1);
Document sub = new Document().Append("c_1",1).Append("c_2",DateTime.Now);
doc.Append("c",sub);
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
Assert.AreEqual(51,writer.CalculateSize(doc));
}
示例2: TestCalculateSizeOfSimpleDoc
public void TestCalculateSizeOfSimpleDoc()
{
Document doc = new Document();
doc.Append("a","a");
doc.Append("b",1);
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
//BsonDocument bdoc = BsonConvert.From(doc);
Assert.AreEqual(21,writer.CalculateSize(doc));
}
示例3: CreateCollection
public Collection CreateCollection(String name, Document options)
{
Document cmd = new Document();
cmd.Append("create", name).Update(options);
db.SendCommand(cmd);
return new Collection(name, connection, this.name);
}
示例4: SaveSettings
public override void SaveSettings(System.Collections.Specialized.StringDictionary settings)
{
using (var mongo = new MongoDbWr())
{
var coll = mongo.BlogDB.GetCollection("settings");
foreach (string key in settings.Keys)
{
Document doc = new Document();
doc.Append("name", key);
doc.Append("value", settings[key]);
coll.Insert(doc);
}
}
}
示例5: CreateCollection
public Collection CreateCollection(String name, Document options)
{
Document command = new Document();
command.Append("create", name).Update(options);
//this.connection.SendCommand(command);
//TODO send command to DB.
return new Collection(name, connection, this.Name);
}
示例6: creatadocFromArrays
private static Document creatadocFromArrays(string[] names, object[] values)
{
if (values.Length != names.Length)
{
throw new MongoXtrasException("MongoCollection.Fill: the length is different");
}
Document doc = new Document();
for (int i = 0; i < names.Length; i++)
{
doc.Append(names[i], values[i]);
}
return doc;
}
示例7: RunQuery
public IEnumerable RunQuery(string server, string database, string port, string query)
{
if (database == string.Empty)
throw new QueryValidationException("You must specify a non-empty database name");
if (query == string.Empty)
throw new QueryValidationException("You must specify a non-empty query");
_db = new Mongo(string.Format("Server={0}:{1}", server, port));
IList<DictionaryBase> documents = new List<DictionaryBase>();
try
{
_db.Connect();
}
catch (SocketException ex)
{
throw new UnknownServerException(string.Format("Unknown server: {0}:{1}", server, port), ex);
}
string[] queryParts = query.Split(':');
string collection = queryParts[0];
if (queryParts.Length > 1)
{
Document spec = new Document();
string where = queryParts[1];
const string LIMIT_TEXT = " limit ";
int limitIndex = where.IndexOf(LIMIT_TEXT);
int limit = 0;
if (limitIndex > -1)
{
string limitText;
if (int.TryParse(where.Substring(limitIndex + LIMIT_TEXT.Length), out limit))
where = where.Substring(0, limitIndex);
}
spec.Append("$where", new Code(where));
_cursor = _db[database][collection].Find(spec, limit, 0);
}
else
_cursor = _db[database][collection].FindAll();
return _cursor.Documents;
//Document d = db[database].SendCommand("db.test.find();");
}
示例8: TestDBRefRoundTrip
public void TestDBRefRoundTrip()
{
Document source = new Document();
source.Append("x",1).Append("ref",new DBRef("refs","ref1"));
BsonDocument bdoc = BsonConvert.From(source);
Document copy = (Document)bdoc.ToNative();
Assert.IsTrue(copy.Contains("ref"));
Assert.IsTrue(copy["ref"].GetType() == typeof(DBRef));
DBRef sref = (DBRef)source["ref"];
DBRef cref = (DBRef)copy["ref"];
Assert.AreEqual(sref.Id, cref.Id);
}
示例9: Find
public ICursor Find(String where)
{
Document spec = new Document();
spec.Append("$where", new Code(where));
return this.Find(spec, 0, 0, null);
}
示例10: CreateUser
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
{
ValidatePasswordEventArgs args =
new ValidatePasswordEventArgs(username, password, true);
OnValidatingPassword(args);
if (args.Cancel)
{
status = MembershipCreateStatus.InvalidPassword;
return null;
}
if (RequiresUniqueEmail && GetUserNameByEmail(email) != "")
{
status = MembershipCreateStatus.DuplicateEmail;
return null;
}
MembershipUser u = GetUser(username, false);
if (u == null)
{
DateTime createDate = DateTime.Now;
if (providerUserKey == null)
{
providerUserKey = Guid.NewGuid();
}
else
{
if (!(providerUserKey is Guid))
{
status = MembershipCreateStatus.InvalidProviderUserKey;
return null;
}
}
try
{
using (var conn = cm.New)
{
var collection = conn.Database.GetCollection("aspnet_members");
Document doc = new Document();
doc.Append("PKID", providerUserKey);
doc.Append("Username", username);
doc.Append("Password", EncodePassword(password));
doc.Append("Email", email);
doc.Append("PasswordQuestion", passwordQuestion);
doc.Append("PasswordAnswer", EncodePassword(passwordAnswer));
doc.Append("IsApproved", isApproved);
doc.Append("Comment", "");
doc.Append("CreationDate", createDate);
doc.Append("LastPasswordChangedDate", createDate);
doc.Append("LastActivityDate", createDate);
doc.Append("ApplicationName", pApplicationName);
doc.Append("IsLockedOut", false);
doc.Append("LastLockedOutDate", createDate);
doc.Append("FailedPasswordAttemptCount", 0);
doc.Append("FailedPasswordAttemptWindowStart", createDate);
doc.Append("FailedPasswordAnswerAttemptCount", 0);
doc.Append("FailedPasswordAnswerAttemptWindowStart", createDate);
collection.Insert(doc);
}
status = MembershipCreateStatus.Success;
}
catch (MongoException e)
{
if (WriteExceptionsToEventLog)
{
WriteToEventLog(e, "CreateUser");
}
status = MembershipCreateStatus.ProviderError;
}
return GetUser(username, false);
}
else
{
status = MembershipCreateStatus.DuplicateUserName;
}
return null;
}
示例11: DropIndex
public void DropIndex(string name)
{
Document cmd = new Document();
cmd.Append("deleteIndexes",this.name).Append("index",name);
db.SendCommand(cmd);
this.refresh();
}
示例12: DoInsert
static void DoInsert(Database db, string col, Document doc)
{
for(int i = 0; i < perTrial; i++){
Document ins = new Document();
doc.CopyTo(ins);
ins.Append("x", i);
db[col].Insert(ins);
}
}
示例13: DropIndex
public void DropIndex(string name)
{
Document cmd = new Document();
cmd.Append("deleteIndexes",this.name).Append("index",name);
db["$cmd"].FindOne(cmd);
this.refresh();
}