如何在Mongodb中使用MongodbRef引用文档以及如何获取组合文档 [英] How to reference a document in Mongodb Using MongodbRef and How to get combined document
问题描述
您好我是Mongo db的新手我有类似的类结构用于存储表情符号和表情符号类别。我在smilies类中创建了一个mongodef属性,用于引用表情符号类别集合但是能够获得表情符号类别名称...
公共类表情符号{
public ObjectId _id {get;组; }
public MongoDBRef scat_name {get;组; }
public string smil_url {get;组; }
public string smil_detail {get;组; }
}
公共类smilies_category {
public ObjectId _id {get;组; }
公共字符串scat_name {get;组; }
}
我使用下面的代码来获取记录和记录即将来临但只有一份文件
函数void getSmilies(){
var refDocument = new BsonDocument {
{$ ref,smil_scat_id},
{$ id,539ef7c2e46b621314956e3b}
};
var query = Query.EQ (smilies_category,refDocument);
var result = db.GetCollection(smilies)。查找(查询)
}
现在我想要的是组合结果集如
_id :ObjectId(539f3ec1e46b62120023d364),
scat_name:Bussines,
smil_url:www.gmail.com,
smil_detail:好的好,
我们怎样才能达到这个目标?
我是否正确行事?
请让我知道解决方案
ref,smil_scat_id},
{
id, $ 53 $ b};
var query = Query.EQ(smilies_category,refDocument);
var result = db.GetCollection(smilies)。查找(查询)
}
现在我想要的是组合结果集如
_id:ObjectId(539f3ec1e46b62120023d364),
scat_name:Bussines,
smil_url:www.gmail.com,
smil_detail:好的,
我们怎样才能实现这个目标?
我是否正确行事?
请让我知道解决方案
Hi I am new to Mongo db I have class structure like this for storing smilies and smilies category. I have made a mongodef property in smilies class for referencing smilies category collection but enable to get smilies category name...
public class smilies {
public ObjectId _id { get; set; }
public MongoDBRef scat_name{ get; set; }
public string smil_url { get; set; }
public string smil_detail { get; set; }
}
public class smilies_category {
public ObjectId _id { get; set; }
public string scat_name { get; set; }
}
and I am using below code for getting the record and records are coming but only from one document
function void getSmilies(){
var refDocument = new BsonDocument {
{"$ref", "smil_scat_id"},
{"$id", "539ef7c2e46b621314956e3b"}
};
var query = Query.EQ("smilies_category", refDocument);
var result = db.GetCollection("smilies").Find(query)
}
Now What I want here is combine resultset like
"_id" : ObjectId("539f3ec1e46b62120023d364"),
"scat_name : "Bussines",
"smil_url" : "www.gmail.com",
"smil_detail" : "Ok fine",
How can we achieve this?
Is I am going right way?
Please let me the know the solution
ref", "smil_scat_id"},
{"
id", "539ef7c2e46b621314956e3b"}
};
var query = Query.EQ("smilies_category", refDocument);
var result = db.GetCollection("smilies").Find(query)
}
Now What I want here is combine resultset like
"_id" : ObjectId("539f3ec1e46b62120023d364"),
"scat_name : "Bussines",
"smil_url" : "www.gmail.com",
"smil_detail" : "Ok fine",
How can we achieve this?
Is I am going right way?
Please let me the know the solution
这篇关于如何在Mongodb中使用MongodbRef引用文档以及如何获取组合文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!