本文整理汇总了C#中MongoDB.Driver.MongoDBRef类的典型用法代码示例。如果您正苦于以下问题:C# MongoDBRef类的具体用法?C# MongoDBRef怎么用?C# MongoDBRef使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MongoDBRef类属于MongoDB.Driver命名空间,在下文中一共展示了MongoDBRef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AttachPackage
//public StandardResult ParserHolders(string[] holderAccounts)
//{
// if (holderAccounts == null || holderAccounts.Length == 0) return Result(iTripExceptionCode.Error_Null_Reference);
// var resp = GetRespository<Holder>();
// var holders = resp.Select(h => holderAccounts.Contains(h.Account)).ToList();
// if (holders.Count == holderAccounts.Length)
// return Result(holders);
// List<Holder> hs = new List<Holder>();
// holderAccounts.ForEach(delegate(string acc)
// {
// if (!holders.Any(h => h.Account == acc))
// hs.Add(new Holder(acc));
// });
// resp.Insert(hs);
// hs.AddRange(holders);
// return Result(hs);
//}
public int AttachPackage(string[] holders, MongoDBRef package)
{
if (holders == null || holders.Length == 0) return 0;
List<PackageHolding> phs = new List<PackageHolding>();
holders.ForEach(a => phs.Add(new PackageHolding(a, package.Id.AsString)));
GetRespository<PackageHolding>().Insert(phs);
return phs.Count;
}
示例2: TestDeserializeMongoDBRef
public void TestDeserializeMongoDBRef() {
var dbRef = new MongoDBRef("test", ObjectId.GenerateNewId());
var c = new C { DbRef = dbRef };
collection.RemoveAll();
collection.Insert(c);
var rehydrated = collection.FindOne();
Assert.IsNull(rehydrated.DbRef.DatabaseName);
Assert.AreEqual(dbRef.CollectionName, rehydrated.DbRef.CollectionName);
Assert.AreEqual(dbRef.Id, rehydrated.DbRef.Id);
}
示例3: ModifyContent
public ActionResult ModifyContent(string formId, string fieldId,ContentAction contentAction)
{
if(formsCollection != null && !string.IsNullOrEmpty(formId) && !string.IsNullOrEmpty(fieldId))
{
Form form = GetForm(formId);
if(form != null)
{
if(DBHelper.GetInstance().GetField(fieldId) != null)
{
MongoDBRef dbref = new MongoDBRef(DBHelper.GetInstance().FieldsCollection().Name,fieldId);
if(new ContentAction[]{ContentAction.Remove,ContentAction.Up,ContentAction.Down}.Contains(contentAction))
{
if(form.Contents.Contains(dbref))
{
if(contentAction == ContentAction.Remove)
{
form.Contents.Remove(dbref);
}
else if(contentAction == ContentAction.Up)
{
LinkedListNode<MongoDBRef> prev = form.Contents.Find(dbref).Previous;
if(prev != null)
{
form.Contents.Remove(dbref);
form.Contents.AddBefore(prev,dbref);
}
}
else if(contentAction == ContentAction.Down)
{
LinkedListNode<MongoDBRef> next = form.Contents.Find(dbref).Next;
if(next != null)
{
form.Contents.Remove(dbref);
form.Contents.AddAfter(next,dbref);
}
}
}
}
else
{
if(!form.Contents.Contains(dbref))
{
form.Contents.AddLast(dbref);
}
}
formsCollection.Save(form);
}
}
}
return RedirectToAction("Index",new{Id = formId});
}
示例4: DBClient
public DBClient(MongoUrl url, MongoDBRef dbRef)
{
if (url == null)
throw new MongoAuthenticationException("Wrong MongoUrl");
if (dbRef == null)
throw new MongoAuthenticationException("Wrong Collection Value");
_dbName = dbRef.DatabaseName;
_collectionName = dbRef.CollectionName;
//this._type = type;
MongoClientSettings setting = MongoClientSettings.FromUrl(url);
_client = new MongoClient(url);
}
示例5: TestDateTimeRefId
public void TestDateTimeRefId() {
var id = ObjectId.GenerateNewId();
var dateTime = BsonConstants.UnixEpoch; ;
var dbRef = new MongoDBRef("collection", dateTime);
var obj = new C { Id = id, DBRef = dbRef };
var json = obj.ToJson();
var expected = "{ '_id' : ObjectId('#id'), 'DBRef' : { '$ref' : 'collection', '$id' : ISODate('1970-01-01T00:00:00Z') } }";
expected = expected.Replace("#id", id.ToString());
expected = expected.Replace("'", "\"");
Assert.AreEqual(expected, json);
var bson = obj.ToBson();
var rehydrated = BsonSerializer.Deserialize<C>(bson);
Assert.IsTrue(bson.SequenceEqual(rehydrated.ToBson()));
}
示例6: TestDocumentRefId
public void TestDocumentRefId() {
var id = ObjectId.GenerateNewId();
var refId = new BsonDocument { { "x", 1 }, { "y", 2 } };
var dbRef = new MongoDBRef("collection", refId);
var obj = new C { Id = id, DBRef = dbRef };
var json = obj.ToJson();
var expected = "{ '_id' : ObjectId('#id'), 'DBRef' : { '$ref' : 'collection', '$id' : { 'x' : 1, 'y' : 2 } } }";
expected = expected.Replace("#id", id.ToString());
expected = expected.Replace("'", "\"");
Assert.AreEqual(expected, json);
var bson = obj.ToBson();
var rehydrated = BsonSerializer.Deserialize<C>(bson);
Assert.IsTrue(bson.SequenceEqual(rehydrated.ToBson()));
}
示例7: TestGuidRefId
public void TestGuidRefId()
{
var id = ObjectId.GenerateNewId();
var guid = Guid.NewGuid();
var dbRef = new MongoDBRef("collection", guid);
var obj = new C { Id = id, DBRef = dbRef };
var json = obj.ToJson();
var expected = "{ '_id' : ObjectId('#id'), 'DBRef' : { '$ref' : 'collection', '$id' : CSUUID('#guid') } }";
expected = expected.Replace("#id", id.ToString());
expected = expected.Replace("#guid", guid.ToString());
expected = expected.Replace("'", "\"");
Assert.AreEqual(expected, json);
var bson = obj.ToBson();
var rehydrated = BsonSerializer.Deserialize<C>(bson);
Assert.IsTrue(bson.SequenceEqual(rehydrated.ToBson()));
}
示例8: TestFetchDBRef
public void TestFetchDBRef() {
var collectionName = "testdbref";
var collection = database.GetCollection(collectionName);
var document = new BsonDocument { { "_id", ObjectId.GenerateNewId() }, { "P", "x" } };
collection.Insert(document);
var dbRef = new MongoDBRef(collectionName, document["_id"].AsObjectId);
var fetched = database.FetchDBRef(dbRef);
Assert.AreEqual(document, fetched);
Assert.AreEqual(document.ToJson(), fetched.ToJson());
var dbRefWithDatabaseName = new MongoDBRef(database.Name, collectionName, document["_id"].AsObjectId);
fetched = server.FetchDBRef(dbRefWithDatabaseName);
Assert.AreEqual(document, fetched);
Assert.AreEqual(document.ToJson(), fetched.ToJson());
Assert.Throws<ArgumentException>(() => { server.FetchDBRef(dbRef); });
}
示例9: button2_Click
private void button2_Click(object sender, EventArgs e)
{
var connectionString = "mongodb://localhost/?safe=true";
var server = MongoServer.Create(connectionString);
var db = server.GetDatabase("Zalagaonica");
byte[] slika_ugovora = File.ReadAllBytes(textBox1.Text);
UgovorClass ugovor = new UgovorClass
{
datumPotpisivanja = dateTimePicker1.Value.ToString(),
datumIsteka = dateTimePicker2.Value.ToString(),
datNovac = Int32.Parse(textBox3.Text),
slikaUgovora = slika_ugovora
};
var collection = db.GetCollection<UgovorClass>("ugovori");
collection.Insert(ugovor);
ovajUgovor = new MongoDBRef("ugovori",ugovor.Id);
//var nc = db.GetCollection<UgovorClass>("ugovori");
//foreach (UgovorClass item in nc.FindAll())
//{
// MessageBox.Show(item.datumIsteka);
//}
}
示例10: MappingAuthor
static async Task MappingAuthor()
{
var client = new MongoClient("mongodb://rpt:[email protected]:27017/forums");
var forums = client.GetDatabase("forums");
var users = forums.GetCollection<BsonDocument>("users");
var threads = forums.GetCollection<BsonDocument>("uwp_threads");
var updates = new List<WriteModel<BsonDocument>>();
await threads.Find(new BsonDocument())
.ForEachAsync(async (thread) => {
var filter = Builders<BsonDocument>.Filter.Eq("id", thread.GetElement("authorId").Value);
var author = await users.Find(filter).FirstOrDefaultAsync();
var dbref = new MongoDBRef("users", author.GetElement("_id").Value.AsObjectId);
updates.Add(new UpdateOneModel<BsonDocument>(new BsonDocument("_id", thread.GetElement("_id").Value), new BsonDocument("$set", new BsonDocument("author", dbref.ToBsonDocument()))));
});
await threads.BulkWriteAsync(updates);
}
示例11: DealPackage
public int DealPackage(MongoDBRef package, string[] holders)
{
IHolderResolver holderResolver = new HolderResolver();
return holderResolver.AttachPackage(holders, package);
}
示例12: UnlinkContact
/// <summary>
/// Unlinks a contact
/// </summary>
/// <param name="link"></param>
private void UnlinkContact(MongoDBRef link)
{
this.LinkedContacts.Remove(link);
Save();
}
示例13: InsertPat
public string InsertPat(mPatInfo pat, string User)
{
MongoServer server = ConnectDB();
var db = server.GetDatabase("hdb");
string pid = "";
try
{
using (server.RequestStart(db))
{
var Usercollection = db.GetCollection<mUser>("Users");
var query = new QueryDocument("UserName", User);
//mUser u = new mUser();
//u.UserName = "123";
//u.PassWord = "123";
mUser entity = Usercollection.FindOne(query);
MongoDBRef r = new MongoDBRef("Users", entity.Id);
var PatCollection = db.GetCollection<mPatInfo>("Pats");
pat.Doctor = r;
PatCollection.Insert(pat);
pid = pat.PatId.ToString();
//collection.Remove(query);
}
return pid;
}
catch (System.Exception ex)
{
return pid;
}
}
示例14: TestInt64RefId
public void TestInt64RefId()
{
var id = ObjectId.GenerateNewId();
var dbRef = new MongoDBRef("collection", 123456789012345L);
var obj = new C { Id = id, DBRef = dbRef };
var json = obj.ToJson();
var expected = "{ '_id' : ObjectId('#id'), 'DBRef' : { '$ref' : 'collection', '$id' : NumberLong('123456789012345') } }";
expected = expected.Replace("#id", id.ToString());
expected = expected.Replace("'", "\"");
Assert.Equal(expected, json);
var bson = obj.ToBson();
var rehydrated = BsonSerializer.Deserialize<C>(bson);
Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
}
示例15: SocetProducts
public SocetProducts(string productId, string warehouseSocetId)
{
WarehouseSocetId = new MongoDBRef("WarehouseSocet", warehouseSocetId);
ProductId = new MongoDBRef("Product", productId);
this.TimeStamp = DateTime.Now;
}