8

Using Mongoose, we can populate reference document

My Document look like this,

var Menu = new Schema({
name: String,
items:[{ type: ObjectId, ref: 'Items' }],

I have stored item document _id in Menu.Items.

So whenever i want to menu with items data, i do the following.

like

menu.findOne().populate( 'items').exec(function(err, menuData ) {
// here with menuData.items we can access referenced document. not just an _id
});

Q1. ) Is there any facility available in .Net C# MongoDb Driver?. Q2. ) How can i store reference of document ?

Thanks

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Hiren S.
  • 2,793
  • 15
  • 25
  • i've been looking to do this too. i'm afraid i need to manually query my sub-documents :( – CurlyFro May 12 '14 at 21:01
  • I can make use of "MongoDBRef". in my entity it will look like this – Hiren S. May 13 '14 at 06:08
  • public MongoDBRef UserRef { get; set; } and whenever i want to access this i can do like this User userObj = db.FetchDBRefAs(Post.UserRef); So first i have to get post object and then i have to Fetch User Object. Here i want list of MongoDBRef. But FetchDBRefAs comes with a single document only. Anyone knows how to get whole list ? – Hiren S. May 13 '14 at 06:10

0 Answers0